Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. need help: image coordinates(x,y) in opencv with mfc Pin

need help: image coordinates(x,y) in opencv with mfc Pin

Scheduled Pinned Locked Moved C / C++ / MFC
c++debugginghelp
10 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jawadali477
    wrote on last edited by
    #1

    hi, below is the complete code that i have developed using opencv with MFC in vs2008. it builds fine and after debugging it shows two different windows, one containing image and other containing static boxes. the purpose of this code is to display image coordinates (x,y) in 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

    #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;

    L 1 Reply Last reply
    0
    • J jawadali477

      hi, below is the complete code that i have developed using opencv with MFC in vs2008. it builds fine and after debugging it shows two different windows, one containing image and other containing static boxes. the purpose of this code is to display image coordinates (x,y) in 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

      #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;

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Use your debugger to check that your mouse event handler gets called when you double click it. Looking at this code it seems to be somewhat complicated by using opencv and MFC; I wonder why you do not just use MFC on its own?

      speaking as ...

      J 1 Reply Last reply
      0
      • L Lost User

        Use your debugger to check that your mouse event handler gets called when you double click it. Looking at this code it seems to be somewhat complicated by using opencv and MFC; I wonder why you do not just use MFC on its own?

        speaking as ...

        J Offline
        J Offline
        jawadali477
        wrote on last edited by
        #3

        i have checked it with some other examples. works fine. but for this program it does not display the coordinates in static boxes. am i defining the handle HWND hwnd correctly??

        L 1 Reply Last reply
        0
        • J jawadali477

          i have checked it with some other examples. works fine. but for this program it does not display the coordinates in static boxes. am i defining the handle HWND hwnd correctly??

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          jawadali477 wrote:

          am i defining the handle HWND hwnd correctly?

          Yes, but you do not initialise it anywhere. In any case you do not need this variable as you already have the pre-defined CWnd::m_hWnd[^] variable which contains the handle to your object's window.

          speaking as ...

          J 1 Reply Last reply
          0
          • L Lost User

            jawadali477 wrote:

            am i defining the handle HWND hwnd correctly?

            Yes, but you do not initialise it anywhere. In any case you do not need this variable as you already have the pre-defined CWnd::m_hWnd[^] variable which contains the handle to your object's window.

            speaking as ...

            J Offline
            J Offline
            jawadali477
            wrote on last edited by
            #5

            can you please elaborate it because i didn't get your point i.e "pre-defined CWnd::m_hWnd[^] variable which contains the handle to your object's window." you see, i'm not good in programming with handles. :(

            L 1 Reply Last reply
            0
            • J jawadali477

              can you please elaborate it because i didn't get your point i.e "pre-defined CWnd::m_hWnd[^] variable which contains the handle to your object's window." you see, i'm not good in programming with handles. :(

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              The pre-defined variable m_hWnd already holds the handle to the window of the dialog, so that is the one to use in your calls to SetDlgItemText().

              jawadali477 wrote:

              i'm not good in programming with handles.

              This is something you need to study as it is fairly key to the whole Windows framework.

              speaking as ...

              J 1 Reply Last reply
              0
              • L Lost User

                The pre-defined variable m_hWnd already holds the handle to the window of the dialog, so that is the one to use in your calls to SetDlgItemText().

                jawadali477 wrote:

                i'm not good in programming with handles.

                This is something you need to study as it is fairly key to the whole Windows framework.

                speaking as ...

                J Offline
                J Offline
                jawadali477
                wrote on last edited by
                #7

                thank you Richard MacCutchan for your replies. i did use m_hWnd in SetDlgItemText() in first place, but at that time it gave the error as m_hWnd :undeclared identifier. you see i'm using a thread to call mouse function. do i need to redefine m_hWnd?? if yes, where??

                L 1 Reply Last reply
                0
                • J jawadali477

                  thank you Richard MacCutchan for your replies. i did use m_hWnd in SetDlgItemText() in first place, but at that time it gave the error as m_hWnd :undeclared identifier. you see i'm using a thread to call mouse function. do i need to redefine m_hWnd?? if yes, where??

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  If your mouse handler is not part of the dialog class then you need to store m_hWnd into a global variable in your OnInitDialog() method. I wonder, however, why you think it necessary to run this in a separate thread and why you are using opencv, when you could accomplish your goal with a much simpler MFC based application.

                  speaking as ...

                  J 1 Reply Last reply
                  0
                  • L Lost User

                    If your mouse handler is not part of the dialog class then you need to store m_hWnd into a global variable in your OnInitDialog() method. I wonder, however, why you think it necessary to run this in a separate thread and why you are using opencv, when you could accomplish your goal with a much simpler MFC based application.

                    speaking as ...

                    J Offline
                    J Offline
                    jawadali477
                    wrote on last edited by
                    #9

                    thank you Richard MacCatchan for replies. i have implemented MFC based application using picture control. i have included bitmap image in picture control and have defined subclass where i have used OnLButtonDblClk to get the co-ordinates of picture control (not image u know) in static box. and it works fine. but i have some questions and need help. 1. how to implement zoom in/out an the scroll option (for large image sizes)? 2. when applying zoom in/out, will the pixel co-ordinates change (i mean if a point is lying on say (x,y) in picture control before zoom in what will happen to its co-ordinates after zoom in)? Regards JAwad

                    L 1 Reply Last reply
                    0
                    • J jawadali477

                      thank you Richard MacCatchan for replies. i have implemented MFC based application using picture control. i have included bitmap image in picture control and have defined subclass where i have used OnLButtonDblClk to get the co-ordinates of picture control (not image u know) in static box. and it works fine. but i have some questions and need help. 1. how to implement zoom in/out an the scroll option (for large image sizes)? 2. when applying zoom in/out, will the pixel co-ordinates change (i mean if a point is lying on say (x,y) in picture control before zoom in what will happen to its co-ordinates after zoom in)? Regards JAwad

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #10

                      1. Google should be your first place to look for some suggestions[^]. 2. As far as I know, the position will remain constant, it is just the scale that changes, but again you may wish to try some research to see if there are any suggestions around.

                      speaking as ...

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups