qq_31873457 2018-02-04 07:51 采纳率: 0%
浏览 3089
已结题

opencv代码无法打开电脑摄像头

电脑为win10 64位 VS2015

// Video.cpp: implementation of the CVideo class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "Fatiguedetection.h"
#include "Video.h"

#ifdef DEBUG
#undef THIS_FILE
static char THIS_FILE[]=
_FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CVideo::CVideo()
{

}

CVideo::~CVideo()
{

}

int CVideo::OpenCamera(HDC hdc, CRect rect)
{
Sleep(3000);
CvCapture *capture;
capture=cvCaptureFromCAM(-1); //捕获摄像头
if(!capture)
{
AfxMessageBox("打开摄像头失败!");
return 1;
}
m_pcapture=capture; //视像头指针传递
m_rect=rect; //获得picture控件的RECT

m_hdc=hdc; //获得picture控件的画图句柄

return -1;

}

void CVideo::PlayCamera()
{
m_pframe = cvQueryFrame(m_pcapture);//获取一帧
if (m_pframe)
{
m_showimage.CopyOf(m_pframe, 1);
m_showimage.DrawToHDC(m_hdc, &m_rect); //显示到控件
}
}

  • 写回答

5条回答 默认 最新

  • Coulson_Zhao 2018-02-04 08:45
    关注

    // ConsoleApplication3.cpp : 定义控制台应用程序的入口点。
    //

    #include "stdafx.h"
    #include

    int main()
    {
    cv::VideoCapture capture_watcher(0);
    cv::Mat Image;
    int flag = 1;
    char inputC = 0;
    while(flag)
    {
    if (!(capture_watcher.read(Image)))
    {
    }
    cv::imshow("Watcher", Image);
    inputC = cv::waitKey(100);
    if (inputC == 112)
    {
    flag = 0;
    }
    }
    return 0;
    }

    同样的配置,打开电脑自带摄像头,按"P"停止,你可以试一下

    评论

报告相同问题?

悬赏问题

  • ¥15 idea右下角设置编码是灰色的
  • ¥15 全志H618ROM新增分区
  • ¥20 jupyter保存图像功能的实现
  • ¥15 在grasshopper里DrawViewportWires更改预览后,禁用电池仍然显示
  • ¥15 NAO机器人的录音程序保存问题
  • ¥15 C#读写EXCEL文件,不同编译
  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符