opencv_tutorials_t7
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
opencv_tutorials_t7 [2016/06/07 15:41] – joaomatos | opencv_tutorials_t7 [2016/06/07 15:50] – joaomatos | ||
---|---|---|---|
Line 4: | Line 4: | ||
I recommend you to type the code on your own to get familiarized with the program language. If you have trouble , the original code is attached bellow ( Running on Visual Studio 2015 + OpenCV 3.1 ) * Check the installation guide to make sure that you linked all the OpenCV modules to your Visual Studio. | I recommend you to type the code on your own to get familiarized with the program language. If you have trouble , the original code is attached bellow ( Running on Visual Studio 2015 + OpenCV 3.1 ) * Check the installation guide to make sure that you linked all the OpenCV modules to your Visual Studio. | ||
+ | |||
+ | |||
---- | ---- | ||
===== Tracking an object using image moments ===== | ===== Tracking an object using image moments ===== | ||
+ | {{ :: | ||
<Code C++ linenums: | <Code C++ linenums: | ||
Line 94: | Line 97: | ||
//Function to track an object using image moments. | //Function to track an object using image moments. | ||
- | void TrackObject(int &x, int & | + | void TrackObject(Mat threshold, Mat &image) { |
//We will not use the threshold image directly we will use a copy | //We will not use the threshold image directly we will use a copy | ||
Line 102: | Line 105: | ||
threshold.copyTo(temp); | threshold.copyTo(temp); | ||
+ | //x and y values for the location of the object | ||
+ | int x = 0, y = 0; | ||
// | // | ||
Line 178: | Line 183: | ||
//matrix storage for binary threshold image | //matrix storage for binary threshold image | ||
Mat threshold; | Mat threshold; | ||
- | //x and y values for the location of the object | + | |
- | int x = 0, y = 0; | + | |
//create slider bars for HSV filtering | //create slider bars for HSV filtering | ||
createTrackbars(); | createTrackbars(); | ||
Line 231: | Line 235: | ||
if (useTrack) | if (useTrack) | ||
{ | { | ||
- | TrackObject(x, y, threshold, coloredimage); | + | TrackObject(threshold, |
} | } | ||
Line 348: | Line 352: | ||
<Code C++ linenums: | <Code C++ linenums: | ||
//Function to track an object using image moments. | //Function to track an object using image moments. | ||
- | void TrackObject(int &x, int & | + | void TrackObject(Mat threshold, Mat &image) { |
//We will not use the threshold image directly we will use a copy | //We will not use the threshold image directly we will use a copy | ||
Line 356: | Line 360: | ||
threshold.copyTo(temp); | threshold.copyTo(temp); | ||
| | ||
+ | //x and y values for the location of the object | ||
+ | int x = 0, y = 0; | ||
+ | |||
//Tracking success. | //Tracking success. | ||
bool objectFound = false; | bool objectFound = false; | ||
Line 542: | Line 549: | ||
Here we create the on/off toggles to use the morphological transformations (by pressing ' | Here we create the on/off toggles to use the morphological transformations (by pressing ' | ||
+ | |||
+ | ---- | ||
+ | <Code C++ linenums: | ||
+ | //show frames | ||
+ | imshow(" | ||
+ | imshow(" | ||
+ | imshow(" | ||
+ | key = waitKey(25); | ||
+ | |||
+ | } | ||
+ | |||
+ | |||
+ | |||
+ | return 0; | ||
+ | } | ||
+ | |||
+ | </ | ||
+ | |||
+ | |
opencv_tutorials_t7.txt · Last modified: 2016/06/07 15:57 by joaomatos