Saturday, 15 February 2014

c++ - Check if a cv::Point is inside a cv::Mat -


Do anybody know that Opencv provides a function to check that a CV :: Point CV :: Is Matt inside? P>

Actually I am doing:

  int x = (current.x - offset); Int y = current.y; If (x> = 0 & y> gt; = 0 & amp; amp; amp; amp; x> matte cols & y & lt; mat.rows) & amp; Amp; (Int) mat.at  (y, x) == 0)) {return cv :: point (x, y); }}   

I would like to know whether anything is faster? Or if it was bad to do this

You can set a cv :: rect as cv :: mat and its are included () method:

  cv :: rect rect (cv :: Point (), matte size ()); CV :: Point P (X, Y); If (rect.contains (p) & amp; mat.at  (y, x) == 0) {return p; }   

Alternatively, you can get an exception to at () if the index is out of range:

UPD: Comments are properly mentioned by @ Antonio, the following work is only in debug mode, because "", which is amazing and different from how it works.

  try {if (Mat.at  (y, x) == 0) {return cv :: point (x, y); }} Hold (CV :: Exception & amp; A) {}   

However, be aware of potential performance fines due to exceptions. If this statement has been executed in a loop or just often you should not use later vision or if it is normal rather than an extraordinary situation.

No comments:

Post a Comment