c++ - Issue accessing/editing pixel location in Mat image -


im trying access , modify pixel values image read opencv. read several posts on how this, however, dont seem work me.

my code:

int main() {   mat src=imread("/home/jaysinh/pictures/shapes.jpg");   cout<<"rows:"<<src.rows<<endl;   cout<<"cols:"<<src.cols<<endl;   cout<<src.at<cv::vec3b>(10,10)[0]<<endl;     waitkey(0);   return 0; } 

gives me result: enter image description here

in image im trying see pixel values @ location (10,10) in image. tried output values of image still special characters.

i tried scalar , unchar types instead of vec3b nothing seems give me appropriate value (between 0-255). type double gives me -nan every pixel location. checked src.type() of image , returned 16 figure 16s type.

how can modify image or somehow access image pixel values of type , modify it?

thanks in advance!

(here image im trying access: enter image description here

cout interprets byte char, , tries print ascii ;) cast int:

cout << int(src.at<vec4b>(3,3)[0]) << endl;    // 100 

or print whole pixel:

cout << src.at<vec4b>(3,3) << endl; // [100, 23, 90] 

yes, can manipulate it:

vec3b & pixel = src.at<vec4b>(3,3); pixel[1] += 5; cout << src.at<vec4b>(3,3) << endl; // [100, 28, 90] 

Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -