2016-10-05 04:45:40 -0600
| received badge | ● Famous Question
(source)
|
2015-11-06 05:47:20 -0600
| received badge | ● Student
(source)
|
2015-11-06 05:44:52 -0600
| received badge | ● Notable Question
(source)
|
2015-05-15 05:28:35 -0600
| received badge | ● Popular Question
(source)
|
2014-03-30 11:41:54 -0600
| commented answer | How to draw a circle on an image using mouse click/events? OK, so I changed else if(flags==CV_EVENT_LBUTTONDOWN) into else if(flags & CV_EVENT_LBUTTONDOWN) and I left only one callback, setMouseCallback("My window",onmouse,&image);
but it still doesn't work ;/ any other ideas? |
2014-03-30 08:52:54 -0600
| answered a question | How to draw a circle on an image using mouse click/events? O.K.
I have changed my program like "berak" said but it still doesn't work.
Where I make a mistake? #include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
void function(int event, int x, int y, int flags, void* param)
{
switch(event){
case CV_EVENT_LBUTTONDOWN:
if(flags & CV_EVENT_FLAG_CTRLKEY)
{
printf("Left button clicked in coordinates %d, %d with CTRL\n",x,y);
}
else if(flags==CV_EVENT_LBUTTONDOWN)
{
printf("Left button clicked in coordinates %d, %d\n",x,y);
}
break;
}
}
void onmouse(int event, int x, int y, int flags, void* param)
{
if(event==CV_EVENT_LBUTTONDOWN)
{
Mat &image = *((Mat*)(param));
circle(image,Point(x,y),50,Scalar(0,255,0),1);
}
}
int main( int argc, char** argv )
{
int key,parameter=5;
Mat image, dst;
/// Read image ( same size, same type )
image = imread("lena.jpg");
if( !image.data )
{
printf("Error \n"); return -1;
}
else
{
printf("Image has been loaded with size %dx%d.\n",image.size);
}
namedWindow("My window", 1);
imshow("My window",image);
setMouseCallback("My window", onmouse, &image);
setMouseCallback("My window",function,¶meter);
printf("what do you want to do?: \n");
while(1)
{
key=waitKey(10);//waits
switch(key)
{
case 'X':
printf("Pressed X \n");
imwrite("image_circle.jpg",image);
return 1;
break;
case 27:
return 1;
break;
}
}
return 0;
}
|
2014-03-25 04:45:07 -0600
| received badge | ● Editor
(source)
|
2014-03-25 04:13:00 -0600
| asked a question | How to draw a circle on an image using mouse click/events? Hi,
My task is to draw a circle on an image using mouse events. I know how to use mouse events, I use for example CV_EVENT_LBUTTONDOWN and thanks to the cvSetMouseCallback and function that i wrote i get mouse click coordinates. I know even how to draw normally a circle, I use function "circle".
But I don't know how to connect together theese two action- mouse events and drawing circle.
I think that I have to get variables x and y from "void funkcja" but i don't know how to do that...any help? My code: #include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
void function(int event, int x, int y, int flags, void* param)
{
switch(event){
case CV_EVENT_LBUTTONDOWN:
if(flags & CV_EVENT_FLAG_CTRLKEY)
{
printf("Left button clicked in coordinates %d, %d with CTRL\n",x,y);
}
else if(flags==CV_EVENT_LBUTTONDOWN)
{
printf("Left button clicked in coordinates %d, %d\n",x,y);
}
break;
}
}
int main( int argc, char** argv )
{
int key,parameter=5;
Mat image, dst;
/// Read image ( same size, same type )
image = imread("lena.jpg");
if( !image.data )
{
printf("Error \n"); return -1;
}
else
{
printf("Image has been loaded with size %dx%d.\n",image.size);
}
circle(image,cvPoint(100,100),50,Scalar(0,255,0),1);//draw circle in point 100,100
namedWindow("My window", 1);
imshow("My window",image);
cvSetMouseCallback("My window",function,¶meter);
std::cout << "what do you want to do?: \n";
while(1)
{
key=cvWaitKey(10);//waits
switch(key)
{
case 'X':
printf("Pressed X \n");
imwrite("image_circle.jpg",image);
return 1;
break;
case 27:
return 1;
break;
}
}
return 0;
}
|