Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Selecting and drawing points on image

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);

            }
        }
    }
}

Selecting and drawing points on image

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;

            }
        }
    }
}

Selecting and drawing points on image

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);