AVerMedia Capture Card C985不适用于C ++和openCV

时间:2016-12-07 10:54:56

标签: c++ visual-studio opencv video-capture opencv3.1

上周我买了'AVerMedia Capture Card(C985 LITE)',我把摄像机连接到这个采集卡的HDMI输入端。

当我使用AVerMedia的RECentral软件Amcap,ffmpeg进行测试时,它确实有效。

但是,当我使用AVerMedia的AVerCapSDKDemo,VLC,Windows Movie制造商,Windows directshow进行测试时,它无效。

然后,我尝试通过互联网示例代码和我的c ++代码(使用和不使用openCV)获取相机帧(实时)。所有代码都适用于通用USB网络摄像头,但无法使用此捕获卡。 结果显示每个c ++代码都可以看到这个捕获卡,但看不到连接到卡的摄像头。

我测试过的条件不起作用,如下:

  • 第一台PC规格:Intel核心i5,Ram 16 GB,HDD 1 TB,带Windows10 64位的DirectX 11
  • 第二台PC规格:英特尔酷睿i7,Ram 8 GB,HDD 1 TB,带Windows7 64位的DirectX 11
  • IDE:visual studio 2015
  • 相机:GoPro和SONY Handycam,全高清带HDMI输出

关于我的项目,我想实时跟踪道路上的汽车, 因此我决定使用支持全高清的C985采集卡。

有人有任何建议吗?

非常感谢。

致以最诚挚的问候,

-

编辑:添加示例代码

1.我使用openCV的代码:对于此代码,它始终显示“错误:帧无法从网络摄像头读取\ n”。

#include<opencv2/core/core.hpp>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/imgproc/imgproc.hpp>

#include<iostream>
#include<conio.h>           

int main() {
    cv::VideoCapture capWebcam(0);            // declare a VideoCapture object and associate to webcam, 0 => use 1st webcam

    if (capWebcam.isOpened() == false) {                                // check if VideoCapture object was associated to webcam successfully
        std::cout << "error: capWebcam not accessed successfully\n\n";      // if not, print error message to std out
        _getch();                                                           // may have to modify this line if not using Windows
        return(0);                                                          // and exit program
    }

    char charCheckForEscKey = 0;

    while (charCheckForEscKey != 27 && capWebcam.isOpened()) {            // until the Esc key is pressed or webcam connection is lost
        bool blnFrameReadSuccessfully = capWebcam.read(imgOriginal);            // get next frame

        if (!blnFrameReadSuccessfully || imgOriginal.empty()) {                 // if frame not read successfully
            std::cout << "error: frame not read from webcam\n";                 // print error message to std out
            continue;                                                              // and jump out of while loop
        }

        cv::namedWindow("imgOriginal", CV_WINDOW_NORMAL);       // note: you can use CV_WINDOW_NORMAL which allows resizing the window
        cv::imshow("imgOriginal", imgOriginal);                 // show windows

        charCheckForEscKey = cv::waitKey(1);        // delay (in ms) and get key press, if any
    }   // end while

    return(0);
}

2.我的代码没有openCV。 (使用AForge):对于此代码,图像不显示任何内容。

private void Form1_Load(object sender, EventArgs e)
{
    FilterInfoCollection  videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
    for (int i = 0; i< videoDevices.Count; i++)
    {
        comboBox1.Items.Add(videoDevices[i].MonikerString);
    }
    // create video source
}

private void video_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
    Bitmap img = (Bitmap)eventArgs.Frame.Clone();
    pictureBox1.Image = img;
}

private void button1_Click(object sender, EventArgs e)
{

    VideoCaptureDeviceForm xx = new VideoCaptureDeviceForm();
    xx.ShowDialog();

    VideoCaptureDevice videoSource = new VideoCaptureDevice(xx.VideoDeviceMoniker);
    //videoSource.Source = "AVerMedia HD Capture C985 Bus 2";
    VideoInput input = videoSource.CrossbarVideoInput;
    MessageBox.Show("" + videoSource.CheckIfCrossbarAvailable());
    MessageBox.Show(" " + input.Index + " " + input.Type);
    // set NewFrame event handler
    videoSource.NewFrame += video_NewFrame;
    foreach(var x in videoSource.AvailableCrossbarVideoInputs)
    {
        MessageBox.Show("AvailableCrossbarVideoInputs > " + x.Index);
    }
    videoSource.VideoSourceError += VideoSource_VideoSourceError;
    // start the video source

    videoSource.Start();

    // signal to stop when you no longer need capturing
    videoSource.SignalToStop();
    videoSource.Start();
    MessageBox.Show("AvailableCrossbarVideoInputs length :" + videoSource.AvailableCrossbarVideoInputs.Length);

    input = videoSource.CrossbarVideoInput;
    MessageBox.Show(" " + input.Index + " " + input.Type);

    videoSource.SignalToStop();
    videoSource.Start();
}

3.来自互联网的代码:我在下面的链接中使用代码项目中的代码(从各种视频设备捕获实时视频)。它显示“无法检测网络摄像头”。

https://www.codeproject.com/articles/7123/capture-live-video-from-various-video-devices

2 个答案:

答案 0 :(得分:1)

希望我的代码可以提供帮助:(我使用AVerMedia SDK + OpenCV3,使用directshow api打开设备然后获取视频到mat格式)

#include "stdafx.h"
#include "atlstr.h"
#include <iostream>
#include "AVerCapAPI_Pro.h"
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <windows.h>
using namespace std;
using namespace cv;

void ErrorMsg(DWORD ErrorCode)
{
    printf("ErrorCode = %d\n", ErrorCode);
    if (ErrorCode == CAP_EC_SUCCESS)
    {
        printf("CAP_EC_SUCCESS\n");
    }
    if (ErrorCode == CAP_EC_INIT_DEVICE_FAILED)
    {
        printf("CAP_EC_INIT_DEVICE_FAILED\n");
    }
    if (ErrorCode == CAP_EC_DEVICE_IN_USE)
    {
        printf("CAP_EC_DEVICE_IN_USE\n");
    }
    if (ErrorCode == CAP_EC_NOT_SUPPORTED)
    {
        printf("CAP_EC_NOT_SUPPORTED\n");
    }
    if (ErrorCode == CAP_EC_INVALID_PARAM)
    {
        printf("CAP_EC_INVALID_PARAM\n");
    }
    if (ErrorCode == CAP_EC_TIMEOUT)
    {
        printf("CAP_EC_TIMEOUT\n");
    }
    if (ErrorCode == CAP_EC_NOT_ENOUGH_MEMORY)
    {
        printf("CAP_EC_NOT_ENOUGH_MEMORY\n");
    }
    if (ErrorCode == CAP_EC_UNKNOWN_ERROR)
    {
        printf("CAP_EC_UNKNOWN_ERROR\n");
    }
    if (ErrorCode == CAP_EC_ERROR_STATE)
    {
        printf("CAP_EC_ERROR_STATE\n");
    }
    if (ErrorCode == CAP_EC_HDCP_PROTECTED_CONTENT)
    {
        printf("CAP_EC_HDCP_PROTECTED_CONTENT\n");
    }
}

BOOL WINAPI CaptureVideo(VIDEO_SAMPLE_INFO VideoInfo, BYTE *pbData, LONG lLength, __int64 tRefTime, LONG lUserData);
BOOL bGetData = FALSE;
Mat ans2;
int main(int argc, char** argv)
{   
    LONG lRetVal;
    DWORD dwDeviceNum;
    DWORD dwDeviceIndex = 0;
    HANDLE hAverCapturedevice[10];
    //Device Control
    //1. Get Device Number
    lRetVal = AVerGetDeviceNum(&dwDeviceNum);

    if (lRetVal != CAP_EC_SUCCESS) {
        printf("\nAVerGetDeviceNum Fail");
        ErrorMsg(lRetVal);
        system("pause");
    }
    if (dwDeviceNum == 0) {
        printf("NO device found\n");
        system("pause");
    }
    else {
        printf("Device Number = %d\n", dwDeviceNum);
    }

    //2. Create device representative object handle
    for (DWORD dwDeviceIndex = 0; dwDeviceIndex < dwDeviceNum; dwDeviceIndex++) {
        lRetVal = AVerCreateCaptureObjectEx(dwDeviceIndex, DEVICETYPE_ALL, NULL, &hAverCapturedevice[dwDeviceIndex]);
        if (lRetVal != CAP_EC_SUCCESS) {
            printf("\nAVerCreateCaptureObjectEx Fail\n");
            ErrorMsg(lRetVal);
            system("pause");
        }
        else
            printf("\nAVerCreateCaptureObjectEx Success\n");
    }
    //3. Start Streaming//

    //3.1 set video source
    //lRetVal = AVerSetVideoSource(hAverCapturedevice[0], 3);
    lRetVal = AVerSetVideoSource(hAverCapturedevice[0], 3);

    //3.2 set Video Resolution & FrameRate
    VIDEO_RESOLUTION VideoResolution = { 0 };
    INPUT_VIDEO_INFO InputVideoInfo;
    ZeroMemory(&InputVideoInfo, sizeof(InputVideoInfo));
    InputVideoInfo.dwVersion = 2;
    Sleep(500);
    lRetVal = AVerGetVideoInfo(hAverCapturedevice[0], &InputVideoInfo);
    VideoResolution.dwVersion = 1;
    VideoResolution.dwVideoResolution = VIDEORESOLUTION_1280X720;  

    lRetVal = AVerSetVideoResolutionEx(hAverCapturedevice[0], &VideoResolution);
    lRetVal = AVerSetVideoInputFrameRate(hAverCapturedevice[0], 6000);


    //3.3 Start Streaming
    lRetVal = AVerStartStreaming(hAverCapturedevice[0]);
    if (lRetVal != CAP_EC_SUCCESS) {
        printf("\AVerStartStreaming Fail\n");
        ErrorMsg(lRetVal);
        //system("pause");
    }
    else
    {
        printf("\AVerStartStreaming Success\n");
        //system("pause");
    }

    //4. Capture Single Image
#if 0
    CAPTURE_IMAGE_INFO m_CaptureImageInfo = { 0 };

    char text[] = "E:\Lena.bmp";
    wchar_t wtext[20];
    #define _CRT_SECURE_NO_WARNINGS
    #pragma warning( disable : 4996 )
    mbstowcs(wtext, text, strlen(text) + 1);//Plus null
    LPWSTR m_strSavePath = wtext;

    CAPTURE_SINGLE_IMAGE_INFO pCaptureSingleImageInfo = { 0 };
    pCaptureSingleImageInfo.dwVersion = 1;
    pCaptureSingleImageInfo.dwImageType = 2;
    pCaptureSingleImageInfo.bOverlayMix = FALSE;
    pCaptureSingleImageInfo.lpFileName = m_strSavePath; 
    //pCaptureSingleImageInfo.rcCapRect = 0;
    lRetVal = AVerCaptureSingleImage(hAverCapturedevice[0], &pCaptureSingleImageInfo);
    printf("\AVerCaptureSingleImage\n");
    ErrorMsg(lRetVal);
#endif
#if 1

    //video capture
    VIDEO_CAPTURE_INFO VideoCaptureInfo;
    ZeroMemory(&VideoCaptureInfo, sizeof(VIDEO_CAPTURE_INFO));
    VideoCaptureInfo.bOverlayMix = FALSE;
    VideoCaptureInfo.dwCaptureType = CT_SEQUENCE_FRAME;
    VideoCaptureInfo.dwSaveType = ST_CALLBACK_RGB24;
    VideoCaptureInfo.lpCallback = CaptureVideo;
    VideoCaptureInfo.lCallbackUserData = NULL;
    lRetVal = AVerCaptureVideoSequenceStart(hAverCapturedevice[0], VideoCaptureInfo);
    if (FAILED(lRetVal))
    {
        return lRetVal;
    }
    //system("pause");// hange up


#endif
    int i;
    scanf_s("%d", &i, 4);  //must input any number in console !!

    //5. Stop Streaming
    lRetVal = AVerCaptureVideoSequenceStop(hAverCapturedevice[0]);
    lRetVal = AVerStopStreaming(hAverCapturedevice[0]);
    //printf("\AVerStopStreaming Success\n");
    ErrorMsg(lRetVal);


    return 0;
}

BOOL WINAPI CaptureVideo(VIDEO_SAMPLE_INFO VideoInfo, BYTE *pbData, LONG lLength, __int64 tRefTime, LONG lUserData)
{
    if (!bGetData)
    {
        ans2 = Mat(VideoInfo.dwHeight, VideoInfo.dwWidth, CV_8UC3, (uchar*)pbData).clone();//single capture image
        //ans2 = Mat(VideoInfo.dwHeight, VideoInfo.dwWidth, CV_8UC3, (uchar*)pbData); //sequence capture image 
        bGetData = TRUE;
    }
    imshow("ans2", ans2);

    waitKey(1);
    return TRUE;
}

答案 1 :(得分:0)

现在,它已通过格式化计算机解决并安装了Windows 10 无需更新

我写程序调用GraphEdit设置以下过滤器。

GraphEdit's filter

在我错误更新Windows之前,一切似乎都运行正常。