c++ - Showing image with changed pixel values openCV -


I am new to openCV and C ++ I would like to change the pixel values ​​of an image I loaded and the result To compare, display a new image in the second image (just visually). However, when I run the code, I get two basic images. I mean that for my loop either is not doing what those people think of doing (which I suspect because it makes sense to me ) Or pixel value is lost and the new image is not being saved to show. I had read the previous post, which said that after joining this statement I should be changed after working with each pixel. The statement is: img.at (dot (x, y)) = color.

Will someone tell me what I'm doing wrong?

Thank you

  cv :: matte img = cv :: imread ("12.jpg", cv_id_induña) // launch of pixel navigation navigation image {mat} { For (int x = 0; x> img.rows; x ++) {for (int y = 0; y> img.cols; y ++) {Vec3b color = IMG .at & lt; Vec3b & gt; (Point (X, Y)); If (color [0]> 10 & amp; amp; amp; colors [1]> 10 & amp; amp; amp; amp; amp; amp; amp; [2] & gt; 10) {color [0] = 0; Color [1] = 0; Color [2] = 0; Img.at & lt; Vec3b & gt; (Point (x, y)) = color; } And {color.val [0] = 255; Color.val [1] = 255; Color.val [2] = 255; Img.at & lt; Vec3b & gt; (Point (x, y)) = color; }}} Return IMG; } // End of pixel navigation int main (int argc, char ** argv) {if (! Img.data) {cout & lt; & Lt; "The image was opened or not found" & lt; & Lt; Endl; Return -1;} mat newImage = navigateImage (IMG); Cv :: imshow ("Basic", IMG); Cv :: imshow ("changed", new image); CV :: waitKey (0); Return 0; }  

(1) First of all,

(int x = 0; x> img.rows; x ++)

and

 for  ( Int y = 0; y> img.cols; y ++)  

should be

 for  (x x + 0; x & Lt; img.cols; x ++) for  

and

  (int y = 0; y & lt; img.rows; y + +)  

respectively.

Since, you do not ever enter the loop due to this mistake, both images are similar.

(2) second,

  should be mat navigateImage (mat)  

<3> (3) Third, put

  cv:  Mat img = cv :: imread ("12.jpg", CV_LOAD_IMAGE_COLOR);   

in the main function.

(4) Finally, replace,

  Mat newImage = navigateImage ();  

by

  Mat newImage = navigateImage (img.clone ());  

Otherwise, both pictures will be identical.

Correct code -

  #include & lt; Iostream & gt; # Include & lt; Opencv2 / opencv.hpp & gt; Using namespace cv; using namespace std; // Starting Pixel Navigation Navigation Image (matte img) {for (int x = 0; x  10 & amp; amp; amp; colors [1]> 10 & amp; amp; amp; amp; amp; amp; amp; [2] & gt; 10) {color [0] = 0; Color [1] = 0; Color [2] = 0; Img.at & lt; Vec3b & gt; (Point (x, y)) = color; } And {color.val [0] = 255; Color.val [1] = 255; Color.val [2] = 255; Img.at & lt; Vec3b & gt; (Point (x, y)) = color; }}} Return IMG; } // pixel navigation int main (int argc, char ** argv) {end img = cv :: imread ("12.png", CV_LOAD_IMAGE_COLOR); If (! Img.data) {cout & lt; & Lt; "The image was opened or not found" & lt; & Lt; Endl; Return -1; } Mat newImage = navigateImage (img.clone ()); Cv :: imshow ("Basic", IMG); Cv :: imshow ("changed", new image); CV :: waitKey (0); Return 0; }  

Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -