Ask Your Question

chinois15's profile - activity

2015-02-04 05:22:58 -0600 received badge  Scholar (source)
2015-01-28 04:46:44 -0600 received badge  Supporter (source)
2015-01-28 04:18:21 -0600 commented question Detect Line on image

before it was not possible to add the image. but now the image is there. when clicked on a point of the line, the program find the 2 last (ending ) point , then i draw the line in green. you can see that for the second line, the program find only one ending point and the meeting point. I hope you can see what i want to say.... Thank you. For the old C-API, i know but how to learn easily the modern API C++? if you have some links of beginners tutorials, please you can help me.... Thanks

2015-01-28 04:09:24 -0600 received badge  Editor (source)
2015-01-28 03:38:48 -0600 asked a question Detect Line on image

image description

I have a edge image containing only a line(i removed all noises). I used a mouse event to click on the one point of the line, then i apply a 3 by 3 window to check all the previous or followings points on the lines. The problem is for the crossing lines: the program detect the 2 ending points for the first line but for the second, it takes the meeting point of the 2 line as ending point of the second(The problem exist when my window has to choose in more than one direction). I don't know if it's clear, my english is not good enough. here is my code

void Temp(IplImage* img, int x, int y, CvPoint *endpoint1, CvPoint *endpoint2, int fs){// findind ending points function
bool up = true;
for (int i = -1; i <= 1; i++){
    for (int j = -1; j <= 1; j++){
        CvScalar v = cvGet2D(img, x + j,y + i);
        if (v.val[0] >= 200 && up){ up = false;  p1.x = x + j; p1.y = y + i; }
        else if (v.val[0] >= 200 && !up){ p2.x = x + j; p2.y = y + i; }
    }
}

if (p1.x != x - 1 && p1.y != y - 1){
    endpoint1->x = p1.x; endpoint1->y = p1.y;
    Temp(img, p2.x, p2.y, endpoint1, endpoint2, 2);
return;
}
else if (p2.x != x + 1 && p2.y != y + 1){ endpoint2->x = p2.x; endpoint2->y = p2.y; return; }

if (fs == 1){ Temp(img, p1.x, p1.y, endpoint1, endpoint2, 1); return; }
else{ Temp(img, p2.x, p2.y, endpoint1, endpoint2, 2); return; }
cvLine(img, cvPoint(P1.x + 2, P1.y), cvPoint(P2.x + 2, P2.y), cvScalar(0, 0, 0), 1, 8, 0);

}

void onMouse(int event, int x, int y, int flags, void* param){// mouse event function
IplImage* cvimg = (IplImage*)param;
switch (event){
case CV_EVENT_LBUTTONDOWN:
    CvScalar v = cvGet2D(cvimg, x, y);
    cout << "Clicked Point:" << x << ", " << y << "/  Value:  " << v.val[0]<<endl;
    if (v.val[0] >= 200){
        Temp(cvimg, x, y, &P1, &P2, 1);
        cout << "EndPoint1 :" << P1.x << ", " << P1.y << endl;
        cout << "EndPoint2 :" << P2.x << ", " << P2.y << endl;
        cout << "---------------------" <<endl;


    }

}

}

2015-01-14 03:40:45 -0600 asked a question 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