1 | initial version |
O.K. I have changed my program like "berak" said but program still doesn't work. Where i make a mistiake?
#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;
}
2 | No.2 Revision |
O.K.
I have changed my program like "berak" said but program it still doesn't work.
Where i I make a mistiake?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;
}