Ask Your Question

Count the number of pixels in a line

asked 2014-06-16 12:57:49 -0600

lp gravatar image

I used the code in the object detection tutorial on the opencv site. After detecting the object a line in drawn to object. I need to know the length of this line in pixels. I used LineIterator to count the length, i says it iterating pixels. I'm new to opencv and want to make sure that i'm doing it right

this is the iterator code:

  LineIterator it = LineIterator(img_matches, scene_corners[0] + offset, scene_corners[1] + offset, 8, false);
  int i;
  for (i = 0; i < it.count; i++, ++it){}
  objectPixels = i;

In the constructor the 4th arg is 4-connected line or 8-connected line what does it mean?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2014-06-17 04:45:20 -0600

The line iterator iterates through a raster line, which means a line as it's drawn. Therefore, you could iterate more pixels than a "mathematical discrete line" (ie count != size of discrete line). But if you want to change/count/... pixels affected by the line drawing, you are using the right iterator. Otherwise, look at the discrete line iteration (not implemented in OpenCV to the best of my knowledge).

The 4-connected and 8-connected lines are respectively a line where the anti-aliasing is computed using 4 neighbors or 8 neighbors. It's usual pixel's neighborhood.

edit flag offensive delete link more

Question Tools


Asked: 2014-06-16 12:57:49 -0600

Seen: 1,154 times

Last updated: Jun 17 '14