Click here to Skip to main content
15,894,955 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: help: image coordinates(x,y) in opencv with mfc Pin
SoMad26-Jun-12 20:32
professionalSoMad26-Jun-12 20:32 
GeneralRe: help: image coordinates(x,y) in opencv with mfc Pin
David Crow27-Jun-12 2:38
David Crow27-Jun-12 2:38 
GeneralRe: help: image coordinates(x,y) in opencv with mfc Pin
SoMad27-Jun-12 4:33
professionalSoMad27-Jun-12 4:33 
GeneralRe: help: image coordinates(x,y) in opencv with mfc Pin
SoMad26-Jun-12 21:23
professionalSoMad26-Jun-12 21:23 
GeneralRe: help: image coordinates(x,y) in opencv with mfc Pin
jawadali4778-Jul-12 22:08
jawadali4778-Jul-12 22:08 
AnswerRe: help: image coordinates(x,y) in opencv with mfc Pin
Albert Holguin27-Jun-12 3:28
professionalAlbert Holguin27-Jun-12 3:28 
GeneralRe: help: image coordinates(x,y) in opencv with mfc Pin
jawadali4778-Jul-12 22:06
jawadali4778-Jul-12 22:06 
GeneralRe: help: image coordinates(x,y) in opencv with mfc Pin
jawadali4771-Jul-12 18:01
jawadali4771-Jul-12 18:01 
hi,
below is the complete code that i have developed. it builds fine and after debugging it shows two different windows, one containing image and other containing static boxes. but when i double click on the image window (which is my mouse event), values of (x,y) coordinates are not displayed in the static boxes (static boxes are in the separate window). please pardon my mistakes.
#include "stdafx.h"
#include "opencv01.h"
#include "opencv01Dlg.h"
#include "highgui.h"
#include "afxwin.h"
#include "cv.h"
#include "math.h"
#include<stdlib.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

void on_mouse( int evt, int x, int y, int flags, void* param );    //defining mouse event
HWND hwnd;   //defining handle

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

	enum { IDD = IDD_ABOUTBOX };

	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support

protected:
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()

Copencv01Dlg::Copencv01Dlg(CWnd* pParent /*=NULL*/)
	: CDialog(Copencv01Dlg::IDD, pParent)
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void Copencv01Dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(Copencv01Dlg, CDialog)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


// Copencv01Dlg message handlers

BOOL Copencv01Dlg::OnInitDialog()
{
	CDialog::OnInitDialog();
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon

	
	AfxBeginThread(MyThreadProc, this); //calling thread

	return TRUE;  // return TRUE  unless you set the focus to a control
}


UINT Copencv01Dlg::MyThreadProc(LPVOID pParam)
    {
     Copencv01Dlg * me = (Copencv01Dlg *)pParam;
     me->MyThreadProc();
     return TRUE;
    }


void Copencv01Dlg::MyThreadProc()
{ 
	//image initialization
	
	IplImage* img = cvLoadImage("box.png", CV_WINDOW_AUTOSIZE);
		cvNamedWindow("map", 0);
		cvShowImage("map", img);

                cvSetMouseCallback("map", on_mouse, NULL);     //calling mouse function

                cvWaitKey(0);
                cvReleaseImage(&img);
		cvDestroyWindow("map");
	
}


void Copencv01Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}
void Copencv01Dlg::OnPaint()
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

HCURSOR Copencv01Dlg::OnQueryDragIcon()
{
	return static_cast<HCURSOR>(m_hIcon);
}

void on_mouse( int evt, int x, int y, int flags, void* param )
{
	CString xaxis, yaxis;

		if (evt == CV_EVENT_LBUTTONDBLCLK)
	{
		
			xaxis.Format(_T("%d"), x);
			yaxis.Format(_T("%d"), y);
			SetDlgItemText(hwnd, IDC_Blue, xaxis);
			SetDlgItemText(hwnd, IDC_Green, yaxis);
	}

}


Jawad
QuestionTaskbar Stays Hidden when Mouse is moved on the Bottom of the Screen Pin
UrbanBlues26-Jun-12 9:38
UrbanBlues26-Jun-12 9:38 
AnswerRe: Taskbar Stays Hidden when Mouse is moved on the Bottom of the Screen Pin
Richard Andrew x6426-Jun-12 10:08
professionalRichard Andrew x6426-Jun-12 10:08 
GeneralRe: Taskbar Stays Hidden when Mouse is moved on the Bottom of the Screen Pin
UrbanBlues26-Jun-12 10:24
UrbanBlues26-Jun-12 10:24 
Questionresource compiler rc2188 error Pin
ForNow26-Jun-12 2:43
ForNow26-Jun-12 2:43 
AnswerRe: resource compiler rc2188 error Pin
Richard MacCutchan26-Jun-12 4:25
mveRichard MacCutchan26-Jun-12 4:25 
GeneralRe: resource compiler rc2188 error Pin
ForNow26-Jun-12 6:28
ForNow26-Jun-12 6:28 
GeneralRe: resource compiler rc2188 error Pin
Richard MacCutchan26-Jun-12 7:07
mveRichard MacCutchan26-Jun-12 7:07 
GeneralRe: resource compiler rc2188 error Pin
ForNow26-Jun-12 12:30
ForNow26-Jun-12 12:30 
GeneralRe: resource compiler rc2188 error Pin
ForNow26-Jun-12 13:21
ForNow26-Jun-12 13:21 
Questionsort a map by Value Pin
NajaR1225-Jun-12 23:00
NajaR1225-Jun-12 23:00 
AnswerRe: sort a map by Value Pin
Chandrasekharan P26-Jun-12 0:21
Chandrasekharan P26-Jun-12 0:21 
AnswerRe: sort a map by Value Pin
Roger Stoltz26-Jun-12 0:34
Roger Stoltz26-Jun-12 0:34 
AnswerRe: sort a map by Value Pin
Chris Losinger26-Jun-12 1:14
professionalChris Losinger26-Jun-12 1:14 
QuestionError CXX0052: Member function not found Pin
AmbiguousName25-Jun-12 19:26
AmbiguousName25-Jun-12 19:26 
SuggestionRe: Error CXX0052: Member function not found Pin
Binu MD25-Jun-12 20:24
Binu MD25-Jun-12 20:24 
AnswerRe: Error CXX0052: Member function not found Pin
Richard MacCutchan25-Jun-12 22:06
mveRichard MacCutchan25-Jun-12 22:06 
AnswerRe: Error CXX0052: Member function not found Pin
fat_boy26-Jun-12 3:10
fat_boy26-Jun-12 3:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.