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: 
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: 
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
Post a Comment