-2

does anyone know how do I calculate the distance between the blue point at the upper shape straight down to the border of that one below? I have the coordinates of the point. I was trying to check the color point by point until it reach the white part of the firgure below, but it is consuming too much hardware. (I start the positionY at the black part, but I may be doing something wrong...)

Binary Shapes

while(true){
        p = pixelColor.ptr<Point3_<uchar> >( positionY, positionX);
        if((p->z==255)&&(p->y==255)&&(p->x==255)){
            cout<<"Found"<<endl;
            break;
        }
        positionY++;
}
Felipe
  • 39
  • 1
  • 5

2 Answers2

0

You could use dichotomy, you take a point half the height, if black, you work on the bottom half, if white, the top one then you do the same etc. until you converge. It's O(log2(height)) while your is O(height). You could however get errors depending the problem (ex: columns with white, black, white, black alternances.

You can also work on a single channel.

However, this is a pretty simple loop, if it's consuming too much hardware, you won't be able to do lot of things by the rest.

Tom A
  • 639
  • 5
  • 10
  • This can be a good technique but you must be careful. A black pixel may mean you are in the black area between the white blobs, or that you are in the black area after the second blob. Similarly, a white pixel may mean you are in the first blob, or maybe the second one. – ChronoTrigger Apr 12 '15 at 01:26
0

Since it is rare that an image has substantial changes 1 pixel in size, you could sample every nth pixel. However, your code looks fine, if there is a speed issue, check for memory leaks or infinite loops in other threads.

Lucas
  • 132
  • 6