select square from position using pointPolygonTest in Android

asked 2013-03-25 11:25:24 -0500

Marwen Z gravatar image

updated 2013-03-25 11:28:46 -0500

The purpose of this method is when I click a square with OnTouch (x,y) in a video he displayed it in another view Here are the steps:

initially an image and a set of square (time varying)

if the user clicks in a position then the algorithm check if he clicked on a square or not

if yes it displays the square in another view using a mask (ROI) else display the initial image the problem that working in console but in Android with jni don't response,

my question is how can i optimize this algorithm or found another way

it can be a performance problem => response time

void displaySquares(  Mat& image, vector<vector<Point> >& squares,int xa,int ya )

bool trouv=false;
vector<Rect> boundRect(squares.size()-squares.size()+1);
for(size_t i = 0; i < squares.size()/3; i++ )
vector<Point2f> points;
  for(size_t j = 0; j < 4; j++ )


if(pointPolygonTest((Mat)points, Point2f(xa,ya), false)>=0)

boundRect[0] = boundingRect( Mat(squares[i]) );

Mat roi(image,boundRect[0]);
Rect boundrect=boundRect[0];
rectangle(image, cv::Point(boundrect.x, boundrect.y),
         cv::Point(boundrect.x + boundrect.width, boundrect.y + boundrect.height), Scalar(0,255,0));

edit retag flag offensive close merge delete