Selecting and drawing points on image

asked 2016-02-28 00:58:19 -0600

rookie gravatar image

updated 2016-02-28 03:13:10 -0600

I am manually selecting points on an image and drawing a circle at those points. However, the circles are not drawn at the point I click on the image, but above it. I'm not sure what's going wrong.

int radius = 4;
int thickness = 2;
int lineType = 7;
int shift = 0;

void mouseEventOne(int event, int x, int y, int, void* param){

    if(event == EVENT_LBUTTONDOWN) {
        Point2f* pt =  (Point2f*)param;
        pt->x =x;
        pt->y =y;
        if (imageFlag == 1 && one.size() < NUM_POINTS) {
            if (pt->x != 0 && pt->y != 0) {
                one.push_back(Point2f(pt->x, pt->y));
                circle(imageOne,
                       Point2f(pt->x, pt->y),
                       radius,
                       Scalar(rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255)),
                       thickness,
                       lineType,
                       shift);
                imageFlag = 2;

            }
        }
    }
} 


int main(int argc, char** argv) {

    char* imagePathOne = argv[1];
    char* imagePathTwo = argv[2];

    imageOne = imread(imagePathOne, 1);
    imageTwo = imread(imagePathTwo, 1);


    if(argc != 3 || !imageOne.data ||!imageTwo.data){
        printf("No image data.\n");
        return -1;
    }
    resize(imageOne, imageOne, imageOne.size()/3, 0, 0, INTER_CUBIC);
    resize(imageTwo, imageTwo, imageTwo.size()/3, 0, 0, INTER_CUBIC);
    Point ptOne, ptTwo;
    namedWindow("ImageOne", 0);
    namedWindow("ImageTwo", 0);

    setMouseCallback("ImageOne", mouseEventOne, (void *) &ptOne);
    setMouseCallback("ImageTwo", mouseEventTwo, (void *) &ptTwo);
edit retag flag offensive close merge delete

Comments

  • where do you set imageFlag ?

  • what is imageOne ?

berak gravatar imageberak ( 2016-02-28 01:32:52 -0600 )edit

I have edited the code to make things more clear. I somehow deleted the imageFlag line while editing. I use the flag to transfer selection to the next image where i select the corresponding point. There is a similar mouse event which select a point and draws the circle and sets the imageFlag to 1.

rookie gravatar imagerookie ( 2016-02-28 03:16:27 -0600 )edit

take a look at my answer to that question

sturkmen gravatar imagesturkmen ( 2016-02-28 09:03:03 -0600 )edit

Thanks, I just saw you answer. I think I've done something similar. Now, I suspect my resize function is causing some trouble. When I don't use resize and use an image with smaller resolution, it seems to work fine :s or that the error minimizes so it becomes hard for me to distinguish.

rookie gravatar imagerookie ( 2016-02-28 11:00:57 -0600 )edit