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);
where do you set
imageFlag
?what is
imageOne
?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 theimageFlag
to 1.take a look at my answer to that question
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.