Ask Your Question
0

How to create a ''tripwire'' to detect a specified contour collision/intersection

asked 2014-05-26 20:23:52 -0500

Sentruos gravatar image

updated 2014-05-30 14:50:49 -0500

I have a school project I've been working on, and to do so I've been using Kyle Hounslow's real-time motion tracking with color tutorial. Link: (https://www.youtube.com/watch?v=bSeFrPrqZ2A) and so far I've filtered out my specific color (blue) and have been able to track it consistently. What I need to know is how to draw a line and add a function to it, so that when my specified contour collides with that line, it activates triggers an action I plan on integrating in the future. I know little next to nothing about C++ so if someone could explain it to me I would find that very helpful. Thanks.

Here is my code so far: (https://dl.dropboxusercontent.com/u/28096936/tuts/objectTrackingTut.cpp) Full code: //objectTrackingTutorial.cpp

//Written by Kyle Hounslow 2013

//Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software") //, to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, //and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

//The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER //LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS //IN THE SOFTWARE.

include <sstream>

include <string>

include <iostream>

include <opencv\highgui.h>

include <opencv\cv.h>

using namespace cv; //initial min and max HSV filter values. //these will be changed using trackbars int H_MIN = 0; int H_MAX = 256; int S_MIN = 0; int S_MAX = 256; int V_MIN = 0; int V_MAX = 256; //default capture width and height const int FRAME_WIDTH = 640; const int FRAME_HEIGHT = 480; //max number of objects to be detected in frame const int MAX_NUM_OBJECTS=50; //minimum and maximum object area const int MIN_OBJECT_AREA = 2020; const int MAX_OBJECT_AREA = FRAME_HEIGHTFRAME_WIDTH/1.5; //names that will appear at the top of each window const string windowName = "Original Image"; const string windowName1 = "HSV Image"; const string windowName2 = "Thresholded Image"; const string windowName3 = "After Morphological Operations"; const string trackbarWindowName = "Trackbars"; void on_trackbar( int, void* ) {//This function gets called whenever a // trackbar position is changed

} string intToString(int number){

std::stringstream ss;
ss << number;
return ss.str();

} void createTrackbars(){ //create window for trackbars

namedWindow(trackbarWindowName,0);
//create memory to store trackbar name on window
char TrackbarName[50];
sprintf( TrackbarName, "H_MIN", H_MIN);
sprintf( TrackbarName, "H_MAX", H_MAX);
sprintf( TrackbarName, "S_MIN", S_MIN);
sprintf( TrackbarName, "S_MAX", S_MAX);
sprintf( TrackbarName, "V_MIN", V_MIN);
sprintf( TrackbarName, "V_MAX", V_MAX);
//create ...
(more)
edit retag flag offensive close merge delete

Comments

hi, if you could paste your code here, instead of the dropbox ?

berak gravatar imageberak ( 2014-05-27 01:18:30 -0500 )edit

Sure, just edited my question, it should be up now.

Sentruos gravatar imageSentruos ( 2014-05-30 14:51:50 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2014-05-30 20:59:00 -0500

You can approximate you object (contour) to a convex hull or find its bounding rectangle. This way, checking the position relative to the line will much much simplified. E.g. finding the intersections with the bounding lines from the approximation.

Here you can find a tutorial on how to draw lines. It is done by calling the line function, supplying an image, where the line will be draw, starting position, end, colour (you can use CV_RGB(red_value, green_value, blue_value)), thickness.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

Stats

Asked: 2014-05-26 20:23:52 -0500

Seen: 1,690 times

Last updated: May 30 '14