User Tools

Site Tools


opencv_tutorials_t6

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_t6 [2016/06/07 14:48] joaomatosopencv_tutorials_t6 [2017/05/13 17:53] (current) – [Understanding the code] acater
Line 44: Line 44:
 const int FRAME_HEIGHT = 480; const int FRAME_HEIGHT = 480;
  
-//Function to create a window with the Trackbars to apply the Thresholding.+//Function to create a window with the Trackbars to apply the Threshold.
  
 void createTrackbars() { void createTrackbars() {
Line 71: Line 71:
  //Defining the erode and dilate properties  //Defining the erode and dilate properties
  //the erode element chosen here is a 3x3 piexels rectangle.  //the erode element chosen here is a 3x3 piexels rectangle.
- //Change the Size argument to optimize your thresholding.  + //Change the Size argument to optimize your threshold.  
- //dilate with 8x8 size element to make the thresholding object more visible+ //dilate with 8x8 size element to make the threshold object more visible
  
  Mat erodeElement = getStructuringElement(MORPH_RECT, Size(3, 3));  Mat erodeElement = getStructuringElement(MORPH_RECT, Size(3, 3));
Line 220: Line 220:
 const int FRAME_HEIGHT = 480; const int FRAME_HEIGHT = 480;
    
-//Function to create a window with the Trackbars to apply the Thresholding.+//Function to create a window with the Trackbars to apply the Threshold.
    
 void createTrackbars() { void createTrackbars() {
Line 243: Line 243:
 </Code> </Code>
  
- The code begins with the same idea of image thresholding. Declaring the variables to be used on the Trackbars windows and defining the function to create the slider bars. You can see the commentaries  [[http://www.daslhub.org/unlv/wiki/doku.php?id=opencv_tutorials_t5|here]]+ The code begins with the same idea of image threshold. Declaring the variables to be used on the Trackbars windows and defining the function to create the slider bars. You can see the commentaries  [[http://www.daslhub.org/unlv/wiki/doku.php?id=opencv_tutorials_t5|here]]
  
  
Line 254: Line 254:
  //Defining the erode and dilate properties  //Defining the erode and dilate properties
  //the erode element chosen here is a 3x3 piexels rectangle.  //the erode element chosen here is a 3x3 piexels rectangle.
- //Change the Size argument to optimize your thresholding.  + //Change the Size argument to optimize your threshold.  
- //dilate with 8x8 size element to make the thresholding object more visible+ //dilate with 8x8 size element to make the threshold object more visible
    
  Mat erodeElement = getStructuringElement(MORPH_RECT, Size(3, 3));  Mat erodeElement = getStructuringElement(MORPH_RECT, Size(3, 3));
Line 268: Line 268:
 </Code> </Code>
  
- Again the same idea of the image thresholding code. To track an object first we need to obtain a binary image with only the object visible - and the morphological transform helps to optimaze the visibility of the thresholded object in the binary image by filtering the noise and expanding the object contour.After obtaining the binary image , we can apply the edge and contour detector and we can track the object by its contour - because the object contour will be the only contour shown in the binary image.+ Again the same idea of the image threshold code. To track an object first we need to obtain a binary image with only the object visible - and the morphological transform helps to optimaze the visibility of the thresholded object in the binary image by filtering the noise and expanding the object contour.After obtaining the binary image , we can apply the edge and contour detector and we can track the object by its contour - because the object contour will be the only contour shown in the binary image.
  
  
Line 440: Line 440:
  
  We show the image with the web camera frame and the contour drawn using the **"imshow"** function and update the key variable value to check if the loop will continue / the morphological transformations will be used or not.  We show the image with the web camera frame and the contour drawn using the **"imshow"** function and update the key variable value to check if the loop will continue / the morphological transformations will be used or not.
 +\\
 +\\
 +The video below demonstrates the program running in real time.
 +{{youtube>h3T0-a4YmPs?medium}}
opencv_tutorials_t6.1465336097.txt.gz · Last modified: by joaomatos