access data of binary image and display coordinates of some points
Hello everyone,
I want access image data of a binary image in order to determine the white point located in the up of the image(having minimal y), down(maximum y), right(maximum x), and in the left(having minimal X) of the image.
here is my code:
cvThreshold(gray, Treshold_img, 150, 255, CV_THRESH_BINARY);
IplConvKernel *element = cvCreateStructuringElementEx(3, 3, 1,1, CV_SHAPE_RECT, NULL );
cvMorphologyEx(Treshold_img, Morphology_img, Temp_img, element, CV_MOP_CLOSE, 2);// remove noises
for (int i = 0; i < Morphology_img->height; i++){
for (int j = 0; j < Morphology_img->width; j++)
{
if ((Morphology_img->imageData[i* Morphology_img->widthStep + j] = 255) && (i<min_y))
{
min_y = i;
min_y_x = j;
}
else if (Morphology_img->imageData[i* Morphology_img->widthStep + j] = 255 && j < min_x)
{
min_x = j;
min_x_y = i;
}
else if (Morphology_img->imageData[i* Morphology_img->widthStep + j] = 255 && i > max_y)
{
max_y = i;
max_y_x = j;
}
else if (Morphology_img->imageData[i* Morphology_img->widthStep + j] = 255 && j >max_x)
{
max_x = j;
max_x_y = i;
}
}
}
The problem is that when i run the code , my Morphology_img become a white image and the coordinate of my points are not correct.
Any help? any Idea?
Thanks
hmm, you probably should stop using the arcane c-api...
(folks here also could help you better then, really, noone is using that kind of code any more)
if your Morphology_img is white, then it is the c stuff (which is deprecated) or the thresholding, are you sure that there are levels lower than 150 ?