OnMouseClick Event

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

OnMouseClick Event

opencv-users mailing list
Hai Everyone
 I have a image , i want to place a tracker on point where i double click the left mouse button , and i have to generate a 5X5 pixel on the double click point and i have to read the x and y coordinates values and print it or display it on the window
 

 Can anyone say me please ,how to place a tracker/marker on mouse click and store coordinates of x and y value..
 

 Please any one help in these is warmly welcomed
 

 With Regard
 Rishiganesh.V
Reply | Threaded
Open this post in threaded view
|

Re: OnMouseClick Event

opencv-users mailing list
hi Rishiganesh,
I guess pygame Library will ideal choice for that If you are using python. you can use all kind of mouse and keyboard event in that.
http://www.pygame.org/download.shtml
see this https://www.pygame.org/docs/ref/mouse.html#pygame.mouse.get_pos
 thanks and regardVijay


     On Tuesday, 1 September 2015 5:11 PM, "[hidden email] [OpenCV]" <[hidden email]> wrote:
   

     Hai EveryoneI have a image , i want to place a tracker on point where i double click the left mouse button , and i have to generate a 5X5 pixel on the double click point and i have to read the x and y coordinates values and print it or display it on the window
Can anyone say me please ,how to place a tracker/marker on mouse click and store coordinates of x and y value..
Please any one help in these is warmly welcomed
With RegardRishiganesh.V  #yiv9256757116 #yiv9256757116 -- #yiv9256757116ygrp-mkp {border:1px solid #d8d8d8;font-family:Arial;margin:10px 0;padding:0 10px;}#yiv9256757116 #yiv9256757116ygrp-mkp hr {border:1px solid #d8d8d8;}#yiv9256757116 #yiv9256757116ygrp-mkp #yiv9256757116hd {color:#628c2a;font-size:85%;font-weight:700;line-height:122%;margin:10px 0;}#yiv9256757116 #yiv9256757116ygrp-mkp #yiv9256757116ads {margin-bottom:10px;}#yiv9256757116 #yiv9256757116ygrp-mkp .yiv9256757116ad {padding:0 0;}#yiv9256757116 #yiv9256757116ygrp-mkp .yiv9256757116ad p {margin:0;}#yiv9256757116 #yiv9256757116ygrp-mkp .yiv9256757116ad a {color:#0000ff;text-decoration:none;}#yiv9256757116 #yiv9256757116ygrp-sponsor #yiv9256757116ygrp-lc {font-family:Arial;}#yiv9256757116 #yiv9256757116ygrp-sponsor #yiv9256757116ygrp-lc #yiv9256757116hd {margin:10px 0px;font-weight:700;font-size:78%;line-height:122%;}#yiv9256757116 #yiv9256757116ygrp-sponsor #yiv9256757116ygrp-lc .yiv9256757116ad {margin-bottom:10px;padding:0 0;}#yiv9256757116 #yiv9256757116actions {font-family:Verdana;font-size:11px;padding:10px 0;}#yiv9256757116 #yiv9256757116activity {background-color:#e0ecee;float:left;font-family:Verdana;font-size:10px;padding:10px;}#yiv9256757116 #yiv9256757116activity span {font-weight:700;}#yiv9256757116 #yiv9256757116activity span:first-child {text-transform:uppercase;}#yiv9256757116 #yiv9256757116activity span a {color:#5085b6;text-decoration:none;}#yiv9256757116 #yiv9256757116activity span span {color:#ff7900;}#yiv9256757116 #yiv9256757116activity span .yiv9256757116underline {text-decoration:underline;}#yiv9256757116 .yiv9256757116attach {clear:both;display:table;font-family:Arial;font-size:12px;padding:10px 0;width:400px;}#yiv9256757116 .yiv9256757116attach div a {text-decoration:none;}#yiv9256757116 .yiv9256757116attach img {border:none;padding-right:5px;}#yiv9256757116 .yiv9256757116attach label {display:block;margin-bottom:5px;}#yiv9256757116 .yiv9256757116attach label a {text-decoration:none;}#yiv9256757116 blockquote {margin:0 0 0 4px;}#yiv9256757116 .yiv9256757116bold {font-family:Arial;font-size:13px;font-weight:700;}#yiv9256757116 .yiv9256757116bold a {text-decoration:none;}#yiv9256757116 dd.yiv9256757116last p a {font-family:Verdana;font-weight:700;}#yiv9256757116 dd.yiv9256757116last p span {margin-right:10px;font-family:Verdana;font-weight:700;}#yiv9256757116 dd.yiv9256757116last p span.yiv9256757116yshortcuts {margin-right:0;}#yiv9256757116 div.yiv9256757116attach-table div div a {text-decoration:none;}#yiv9256757116 div.yiv9256757116attach-table {width:400px;}#yiv9256757116 div.yiv9256757116file-title a, #yiv9256757116 div.yiv9256757116file-title a:active, #yiv9256757116 div.yiv9256757116file-title a:hover, #yiv9256757116 div.yiv9256757116file-title a:visited {text-decoration:none;}#yiv9256757116 div.yiv9256757116photo-title a, #yiv9256757116 div.yiv9256757116photo-title a:active, #yiv9256757116 div.yiv9256757116photo-title a:hover, #yiv9256757116 div.yiv9256757116photo-title a:visited {text-decoration:none;}#yiv9256757116 div#yiv9256757116ygrp-mlmsg #yiv9256757116ygrp-msg p a span.yiv9256757116yshortcuts {font-family:Verdana;font-size:10px;font-weight:normal;}#yiv9256757116 .yiv9256757116green {color:#628c2a;}#yiv9256757116 .yiv9256757116MsoNormal {margin:0 0 0 0;}#yiv9256757116 o {font-size:0;}#yiv9256757116 #yiv9256757116photos div {float:left;width:72px;}#yiv9256757116 #yiv9256757116photos div div {border:1px solid #666666;height:62px;overflow:hidden;width:62px;}#yiv9256757116 #yiv9256757116photos div label {color:#666666;font-size:10px;overflow:hidden;text-align:center;white-space:nowrap;width:64px;}#yiv9256757116 #yiv9256757116reco-category {font-size:77%;}#yiv9256757116 #yiv9256757116reco-desc {font-size:77%;}#yiv9256757116 .yiv9256757116replbq {margin:4px;}#yiv9256757116 #yiv9256757116ygrp-actbar div a:first-child {margin-right:2px;padding-right:5px;}#yiv9256757116 #yiv9256757116ygrp-mlmsg {font-size:13px;font-family:Arial, helvetica, clean, sans-serif;}#yiv9256757116 #yiv9256757116ygrp-mlmsg table {font-size:inherit;font:100%;}#yiv9256757116 #yiv9256757116ygrp-mlmsg select, #yiv9256757116 input, #yiv9256757116 textarea {font:99% Arial, Helvetica, clean, sans-serif;}#yiv9256757116 #yiv9256757116ygrp-mlmsg pre, #yiv9256757116 code {font:115% monospace;}#yiv9256757116 #yiv9256757116ygrp-mlmsg * {line-height:1.22em;}#yiv9256757116 #yiv9256757116ygrp-mlmsg #yiv9256757116logo {padding-bottom:10px;}#yiv9256757116 #yiv9256757116ygrp-msg p a {font-family:Verdana;}#yiv9256757116 #yiv9256757116ygrp-msg p#yiv9256757116attach-count span {color:#1E66AE;font-weight:700;}#yiv9256757116 #yiv9256757116ygrp-reco #yiv9256757116reco-head {color:#ff7900;font-weight:700;}#yiv9256757116 #yiv9256757116ygrp-reco {margin-bottom:20px;padding:0px;}#yiv9256757116 #yiv9256757116ygrp-sponsor #yiv9256757116ov li a {font-size:130%;text-decoration:none;}#yiv9256757116 #yiv9256757116ygrp-sponsor #yiv9256757116ov li {font-size:77%;list-style-type:square;padding:6px 0;}#yiv9256757116 #yiv9256757116ygrp-sponsor #yiv9256757116ov ul {margin:0;padding:0 0 0 8px;}#yiv9256757116 #yiv9256757116ygrp-text {font-family:Georgia;}#yiv9256757116 #yiv9256757116ygrp-text p {margin:0 0 1em 0;}#yiv9256757116 #yiv9256757116ygrp-text tt {font-size:120%;}#yiv9256757116 #yiv9256757116ygrp-vital ul li:last-child {border-right:none !important;}#yiv9256757116

 
Reply | Threaded
Open this post in threaded view
|

Re: OnMouseClick Event

opencv-users mailing list
In reply to this post by opencv-users mailing list
Hello FriendsThank you  for your kind reply , now i will try with pygame modules to check whether it satisfy my need.
With Regard
Rishiganesh.V
Reply | Threaded
Open this post in threaded view
|

Re: OnMouseClick Event

keghn

/*
http://opencv-users.1802565.n2.nabble.com/GrabCut-Image-Segmentation-using-openCV-td7585599.html

 Use mouse, with left button down, to drag out your box in the image.
 Push right button on mouse to show image of selection
 Hit return to quit.

 The selected image will print under the main image, so move it.

g++ p.cpp -o p `pkg-config --cflags --libs opencv`

*/


#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/video/background_segm.hpp>
#include <opencv2/opencv.hpp>
#include <stdio.h>
#include <iostream>
#include <sstream>

using namespace cv;
using namespace std;

/* GrabCut algorithm in a very simple way using opencv implementations*/

Point point1, point2;
int drag = 0;
Rect rect;
Mat img, roiImg;
bool select_flag = true;
Mat rectimg;
vector<Point>Pf,Pb;


void mouseHandler(int event, int x, int y, int flags, void* param)
{
        if (event == CV_EVENT_LBUTTONDOWN && !drag)
        {
                point1 = Point(x, y);
                drag = 1;
        }

        else if (event == CV_EVENT_MOUSEMOVE && drag)
        {
               
                Mat img1 = img.clone();
                point2 = Point(x, y);
                rectangle(img1, point1, point2, CV_RGB(255, 0, 0), 3, 8, 0);
                imshow("image", img1);
                       
        }

        else if (event == CV_EVENT_LBUTTONUP && drag)
        {
                point2 = Point(x, y);
                rect = Rect(point1.x,point1.y,x-point1.x,y-point1.y);
                drag = 0;
                roiImg = img(rect);
                       
        }

        else if (event == CV_EVENT_RBUTTONDOWN)
        {
               
                select_flag = false;
                drag = 0;
                imshow("ROI", roiImg);
               
        }
}

int main(int argc, char** argv)
{
       
        img= imread(argv[1]);
        Mat img2=img.clone();
        cv::Mat foreground(img.size(),CV_8UC3,cv::Scalar(255,255,255));
        Mat result(img.size(),CV_8UC1);
        Mat fg,bg;
        namedWindow("image",1);
        imshow("image", img);
        int i;
        setMouseCallback("image", mouseHandler, NULL);
/*
        cout<<"Enter number of iteration"<<endl;
        cin>>i;

        while((select_flag==true)&&(waitKey(0)!=27))
        {
               
                grabCut(img,result,rect,bg,fg,i,GC_INIT_WITH_RECT);
                cv::compare(result,cv::GC_PR_FGD,result,cv::CMP_EQ);
                img.copyTo(foreground,result);
                imshow("image3",foreground);
               
        }
*/
        waitKey(0);
        return 0;
}
Reply | Threaded
Open this post in threaded view
|

Re: OnMouseClick Event

keghn

/*


 Left mouse button creates a picture 100 x 100 of center, from the main image.
 if selected too close to the side the progamm will crash.

 Hit return to quit.

 The selected image will print under the main image, so move it.

g++ p.cpp -o p `pkg-config --cflags --libs opencv`

*/


#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/video/background_segm.hpp>
#include <opencv2/opencv.hpp>
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <unistd.h>


using namespace cv;
using namespace std;

/* GrabCut algorithm in a very simple way using opencv implementations*/

Point point1, point2;
int drag = 0;
Rect rect;
Mat img, roiImg;
bool select_flag = true;
Mat rectimg;
vector<Point>Pf,Pb;


void mouseHandler(int event, int x, int y, int flags, void* param)
{


        if (event == CV_EVENT_LBUTTONDOWN)
                {
                          point1 = Point(x, y);

//  rect = Rect(point1.x,point1.y,x-point1.x,y-point1.y);
                          rect = Rect(point1.x,point1.y,100,100);
                roiImg = img(rect);
                select_flag = false;
// drag = 0;
                imshow("ROI", roiImg);
        }

}



int main(int argc, char** argv)
{
       
        img= imread(argv[1]);
        Mat img2=img.clone();
        cv::Mat foreground(img.size(),CV_8UC3,cv::Scalar(255,255,255));
        Mat result(img.size(),CV_8UC1);
        Mat fg,bg;
        namedWindow("image",1);
        imshow("image", img);
        int i;
        setMouseCallback("image", mouseHandler, NULL);

        waitKey(0);
        return 0;
}