Ask Your Question
0

execute program when detected color is on specific side of frame

asked 2015-10-21 13:11:59 -0500

I am wanting to write a program which detects an object based on it's color (let's say red, for instance), and whenever it finds the object on a certain side of the screen, I want the opencv code to execute another program. Like if the object was within a range on the right hand side of the frame, I want the OpenCV program to run another program (perhaps through the C++ system() function). Same thing would apply for the middle and right hand side of the frame. I have divided the frame into three pieces, left, right, and center. And I want the OpenCV code to execute a program depending on where in the frame the object is found.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2015-10-22 04:24:45 -0500

That seems fairly simple to me

  1. Segment the red blob and add a tracker to it. A helpfull tutorial can be this one
  2. In your program define crossing borders, for example vertical lines.
  3. Now just do simple checks at each frame with if statements, checking if the position of your tracked ball is somewhere crossing a border.

For example if you have a border at x=15, x =100 and x=250 (all vertical lines), then you can apply these if loops

if(position.x < 15){
   //execute first code
}elseif( 15 < position.x && position.x < 100){
   //execute second code
}elseif( 100 < position.x && position.x < 250){
   //excute third code
}else{
  //you are in the fourth code part
}
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2015-10-21 13:11:59 -0500

Seen: 65 times

Last updated: Oct 22 '15