User Tools

Site Tools


opencv_tutorials_t2

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
opencv_tutorials_t2 [2016/06/06 15:25] joaomatosopencv_tutorials_t2 [2017/05/13 17:04] (current) – [Understanding the Code] acater
Line 7: Line 7:
 {{::pixel_value_and_location.rar|Pixel Value and Location}} {{::pixel_value_and_location.rar|Pixel Value and Location}}
  
-{{ :pixel_value.jpg?direct |}}+
  
 ---- ----
  
-===== Code =====+===== Pixel Operations =====
  
 +{{ :pixel_value.jpg?direct |}}
  
 <Code:c++ linenums:1> <Code:c++ linenums:1>
Line 25: Line 26:
 Mat image; Mat image;
  
-//function to get the pixel RGB value at the given y row and x column.+//function to get the pixel RGB value at the given y column and x row
 static void onMouse(int event, int x, int y, int f, void*) { static void onMouse(int event, int x, int y, int f, void*) {
  
Line 50: Line 51:
  imshow("Pixel position and RGB values", image);  imshow("Pixel position and RGB values", image);
  
- //use function setMouseCallback with our onMouse function to get the piexel properties+ //use function setMouseCallback with our onMouse function to get the pixel properties
  //on the mouse pointer location  //on the mouse pointer location
  setMouseCallback("Pixel position and RGB values", onMouse, 0);  setMouseCallback("Pixel position and RGB values", onMouse, 0);
Line 67: Line 68:
  
 <Code:c++ linenums:11> <Code:c++ linenums:11>
-//function to get the pixel RGB value at the given y row and x column.+//function to get the pixel RGB value at the given y column and x row
 static void onMouse(int event, int x, int y, int f, void*) { static void onMouse(int event, int x, int y, int f, void*) {
  
Line 81: Line 82:
 </Code> </Code>
  
- We can define a function to be called on the main program to get the RGB values (On OpenCV we always read BGR ) and the pixel's row(y) and column(x). **"Vec3b"** is the type of the pix variable , which will store the B[0], G[1] and R[2] color values from the image (which can be accessed using **".val[]"** ). The pix variable will receive the values from the Mat variable image - and using **"image.at<Vec3b>(y, x)"** we assign the pixel values from the image variable at the position (y,x) - which is where the mouse is - to the pix variable. Creating three integer variables we can access what is stored on the pix vector using ".val[]". This function will be called using the **"setMouseCallback"** command on the main program. This function will not return any value , it will just print the values on the CMD window opened when you run the program. To display any variables on the cmd Window we use the **"cout <<"** command. If we want to display a text message we need to use **" "** , and if it is a variable we just put the variable name . To separate the string from the variables we use **" << "** .+ We can define a function to be called on the main program to get the RGB values (On OpenCV we always read BGR ) and the pixel's row(x) and column(y). **"Vec3b"** is the type of the pix variable , which will store the B[0], G[1] and R[2] color values from the image (which can be accessed using **".val[]"** ). The pix variable will receive the values from the Mat variable image - and using **"image.at<Vec3b>(y, x)"** we assign the pixel values from the image variable at the position (y,x) - which is where the mouse is - to the pix variable. Creating three integer variables we can access what is stored on the pix vector using ".val[]". This function will be called using the **"setMouseCallback"** command on the main program. This function will not return any value , it will just print the values on the CMD window opened when you run the program. To display any variables on the CMD Window we use the **"cout <<"** command. If we want to display a text message we need to use **" "** , and if it is a variable we just put the variable name . To separate the string from the variables we use **" << "** .
  
  
Line 94: Line 95:
  
 On the main program we call our onMouse function using the setMouseCallback . It will set the mouse handler for the  first argument window (which we opened using the imread function ). On this case we don't set any event (just call if a certain mouse button is pressed ). If you want to call the function just in specific cases , you can find an example [[http://docs.opencv.org/2.4/modules/highgui/doc/user_interface.html|Here]] on the setMouseCallback section. On the main program we call our onMouse function using the setMouseCallback . It will set the mouse handler for the  first argument window (which we opened using the imread function ). On this case we don't set any event (just call if a certain mouse button is pressed ). If you want to call the function just in specific cases , you can find an example [[http://docs.opencv.org/2.4/modules/highgui/doc/user_interface.html|Here]] on the setMouseCallback section.
 +\\
 +\\
 +The video below will demonstrate the program in real time.
 +{{youtube>rYMtRWtgx9Q?medium}}
opencv_tutorials_t2.1465251945.txt.gz · Last modified: by joaomatos