Home > Software engineering >  Vs2015 and opencv3.1.0 in MFC raised open cameras, camera broadly to open up, but couldn't disp
Vs2015 and opencv3.1.0 in MFC raised open cameras, camera broadly to open up, but couldn't disp

Time:10-27

Refer to http://blog.csdn.net/watkinsong/article/details/7360941
//Fire2Dlg. CPP: implementation file 
//

# include "stdafx. H"
# include "Fire2. H"
# include "Fire2Dlg. H"
# include "afxdialogex. H"
# include "CvvImage. H"

# ifdef _DEBUG
# define new DEBUG_NEW
# endif

CvCapture * capture;
HDC HDC.
The CDC * pDC.
The CWnd * PWND.
CRect the rect.
IplImage * fireImage;
CvvImage m_CvvImage;
IplImage * frame;

//for application "about" menu item CAboutDlg dialog

The class CAboutDlg: public CDialogEx
{
Public:
CAboutDlg ();

//data dialog
# ifdef AFX_DESIGN_TIME
Enum {IDD=IDD_ABOUTBOX};
# endif

Protected:
Virtual void DoDataExchange (CDataExchange * symbol;//support DDX/DDV

//implementation
Protected:
DECLARE_MESSAGE_MAP ()
};

CAboutDlg: : CAboutDlg () : CDialogEx (IDD_ABOUTBOX)
{
}

Void CAboutDlg: : DoDataExchange (CDataExchange * symbol)
{
CDialogEx: : DoDataExchange (symbol);
}

BEGIN_MESSAGE_MAP (CAboutDlg CDialogEx)
END_MESSAGE_MAP ()


//CFire2Dlg dialog



CFire2Dlg: : CFire2Dlg (pParent/*=NULL CWnd * */)
: CDialogEx (IDD_FIRE2_DIALOG, pParent)
{
M_hIcon=AfxGetApp () - & gt; LoadIcon (IDR_MAINFRAME);
}

Void CFire2Dlg: : DoDataExchange (CDataExchange * symbol)
{
CDialogEx: : DoDataExchange (symbol);
}

BEGIN_MESSAGE_MAP (CFire2Dlg CDialogEx)
ON_WM_SYSCOMMAND ()
ON_WM_PAINT ()
ON_WM_QUERYDRAGICON ()
ON_BN_CLICKED (IDC_Camera, & amp; CFire2Dlg: : OnBnClickedCamera)
ON_WM_TIMER ()
END_MESSAGE_MAP ()


//CFire2Dlg message handler

BOOL CFire2Dlg: : OnInitDialog ()
{
CDialogEx: : OnInitDialog ();

//will "about... "Menu item added to the system menu,

//IDM_ABOUTBOX must be in the system command range,
ASSERT ((IDM_ABOUTBOX & amp; 0==IDM_ABOUTBOX xfff0));
ASSERT (IDM_ABOUTBOX & lt; 0 xf000);

CMenu * pSysMenu=GetSystemMenu (FALSE);
If (pSysMenu!=NULL)
{
BOOL bNameValid;
Cstrings strAboutMenu;
BNameValid=strAboutMenu. LoadString (IDS_ABOUTBOX);
ASSERT (bNameValid);
if (! StrAboutMenu. IsEmpty ())
{
PSysMenu - & gt; The AppendMenu (MF_SEPARATOR);
PSysMenu - & gt; AppendMenu (MF_STRING IDM_ABOUTBOX, strAboutMenu);
}
}

//set this dialog ICONS, when the application is the main window is not a dialog, the framework will automatically
//do this
SetIcon (m_hIcon, TRUE);//set the large icon
SetIcon (m_hIcon, FALSE);//set the small icon

ShowWindow (SW_MINIMIZE);

//TODO: add additional initialization code in the
PWND=GetDlgItem (IDC_STATIC);
This - & gt; MoveWindow (410, 160, 765, 598);
PWND - & gt; MoveWindow (24, 85, 526, 416);

PDC=PWND - & gt; GetDC ();
HDC=pDC - & gt; GetSafeHdc ();
PWND - & gt; GetClientRect (& amp; The rect);

return TRUE;//unless set focus to the control, return TRUE
}

Void CFire2Dlg: : OnSysCommand (UINT nID, LPARAM LPARAM)
{
If ((nID & amp; 0 xfff0)==IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
DlgAbout. DoModal ();
}
The else
{
CDialogEx: : OnSysCommand (nID, lParam);
}
}

//if the dialog box to add a minimize button, you need the following code
//to draw the icon, to use the document/view model of MFC application,
//it will be done automatically by the framework,

Void CFire2Dlg: : OnPaint ()
{
If (IsIconic ())
{
CPaintDC dc (this);//for drawing device context

The SendMessage (WM_ICONERASEBKGND, reinterpret_cast & lt; WPARAM> (dc) GetSafeHdc ()), 0);

//make the icon is centered within the workspace rectangular
Int cxIcon=GetSystemMetrics (SM_CXICON);
Int cyIcon=GetSystemMetrics (SM_CYICON);
CRect the rect.
GetClientRect (& amp; The rect);
Int x=(the rect. Width () - cxIcon + 1)/2;
Int y=(the rect. Height () - cyIcon + 1)/2;

//draw the icon
Dc. DrawIcon (x, y, m_hIcon);
}
The else
{
CDialogEx: : OnPaint ();
}
}

//when the user drag minimize window system call this function to obtain the cursor
//show,
HCURSOR CFire2Dlg: : OnQueryDragIcon ()
{
Return static_cast & lt; HCURSOR> (m_hIcon);
}



Void CFire2Dlg: : OnBnClickedCamera ()
{
//TODO: add the control notification handler code
The capture=0;
The capture=cvCaptureFromCAM (0);//0 represents the computer itself camera, 1, 2, 3, 4,,,,,,,, on behalf of the external camera
IplImage * frame=cvQueryFrame (capture);
M_CvvImage. CopyOf (frame, 1);
M_CvvImage. DrawToHDC (hDC, & amp; The rect);
The SetTimer (2, 40, NULL);
}


Void CFire2Dlg: : OnTimer (UINT_PTR nIDEvent)
{


CRect rc;
The CWnd * pWnd=GetDlgItem (IDC_STATIC);
PWnd - & gt; GetClientRect (rc);
IplImage * frame=cvQueryFrame (capture);
M_CvvImage. CopyOf (frame, 1);
M_CvvImage. DrawToHDC (hDC, & amp; The rect);


CDialogEx: : OnTimer (nIDEvent);
}

CodePudding user response:

Set in the device manager enabled cameras,
Please check the return values of each function call

CodePudding user response:

Isn't display images, how to know opened? In addition you display content camera code? Imshow?

CodePudding user response:

Look your Debug debugging, which function failed? Or make a breakpoint, look at the key functions performed? Where or failed?
  • Related