视频捕获只能在示例代码中进行,而不能在我自己的项目中进行

时间:2019-01-20 12:14:54

标签: opencv openni orbbec

我使用Cmake使用openni2构建了opencv,并且成功运行了 OpenCV.sln 中的示例“ openni_capture ”。它清楚地显示了正在捕获的视频。我正在使用 Orbbec Astra 相机。

但是当我尝试制作自己的项目时,复制并粘贴代码并运行它,即使成功构建,它也会显示“ 无法打开捕获对象”。

代码如下。问题是在示例项目中' capture.isOpened()'为TRUE,但在我自己的项目中为FALSE,与示例项目具有完全相同的代码。

#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"

#include <iostream>

using namespace cv;
using namespace std;

static void colorizeDisparity( const Mat& gray, Mat& rgb, double maxDisp=-1.f, float S=1.f, float V=1.f )
{
.
.
.
}

static float getMaxDisparity( VideoCapture& capture )
{
.
.
.
}

    static void printCommandLineParams()
{
    cout << "-cd=       Colorized disparity? (0 or 1; 1 by default) Ignored if disparity map is not selected to show." << endl;
    cout << "-fmd=      Fixed max disparity? (0 or 1; 0 by default) Ignored if disparity map is not colorized (-cd 0)." << endl;
    cout << "-mode=     image mode: resolution and fps, supported three values:  0 - CAP_OPENNI_VGA_30HZ, 1 - CAP_OPENNI_SXGA_15HZ," << endl;
    cout << "          2 - CAP_OPENNI_SXGA_30HZ (0 by default). Ignored if rgb image or gray image are not selected to show." << endl;
    cout << "-m=        Mask to set which output images are need. It is a string of size 5. Each element of this is '0' or '1' and" << endl;
    cout << "          determine: is depth map, disparity map, valid pixels mask, rgb image, gray image need or not (correspondently), ir image" << endl ;
    cout << "          By default -m=010100 i.e. disparity map and rgb image will be shown." << endl ;
    cout << "-r=        Filename of .oni video file. The data will grabbed from it." << endl ;
}

static void parseCommandLine( int argc, char* argv[], bool& isColorizeDisp, bool& isFixedMaxDisp, int& imageMode, bool retrievedImageFlags[],
                       string& filename, bool& isFileReading )
{
    filename.clear();
    cv::CommandLineParser parser(argc, argv, "{h help||}{cd|0|}{fmd|0|}{mode|-1|}{m|000100|}{r||}");
    if (parser.has("h"))
    {
        help();
        printCommandLineParams();
        exit(0);
    }
    isColorizeDisp = (parser.get<int>("cd") != 0);
    isFixedMaxDisp = (parser.get<int>("fmd") != 0);
    imageMode = parser.get<int>("mode");
    int flags = parser.get<int>("m");
    isFileReading = parser.has("r");
    if (isFileReading)
        filename = parser.get<string>("r");
    if (!parser.check())
    {
        parser.printErrors();
        help();
        exit(-1);
    }
    if (flags % 1000000 == 0)
    {
        cout << "No one output image is selected." << endl;
        exit(0);
    }
    for (int i = 0; i < 6; i++)
    {
        retrievedImageFlags[5 - i] = (flags % 10 != 0);
        flags /= 10;
    }
}

int main( int argc, char* argv[] )
{
    bool isColorizeDisp, isFixedMaxDisp;
    int imageMode;
    bool retrievedImageFlags[6];
    string filename;
    bool isVideoReading;
    parseCommandLine( argc, argv, isColorizeDisp, isFixedMaxDisp, imageMode, retrievedImageFlags, filename, isVideoReading );

    cout << "Device opening ..." << endl;
    VideoCapture capture;
    if( isVideoReading )
        capture.open( filename );
    else
    {
        capture.open( CAP_OPENNI2 );
        if (!capture.isOpened())
        {
            capture.open(CAP_OPENNI);
        }
    }

    cout << "done." << endl;

    if( !capture.isOpened() )
    {
        cout << "Can not open a capture object." << endl;
        return -1;
    }
.
.
.

我在VC ++目录中添加了包含该目录的目录

C:\ OpenCV_end \ Source \ opencv-3.4.0 \ build \ install \ include,C:\ Program Files \ OpenNI2 \ Include

我将其添加到VC ++目录库目录中

C:\ OpenCV_end \ Source \ opencv-3.4.0 \ build \ install \ x64 \ vc14 \ lib,C:\ Program Files \ OpenNI2 \ Lib

我在链接器输入中添加了

opencv_world340d.lib,OpenNI2.lib

,然后将dll文件复制到包含项目源的文件夹中。 opencv_world340d.dll以及C:\ Program Files \ OpenNI2 \ Redist中的所有文件

但它永远都不想工作。请帮助我

谢谢。

0 个答案:

没有答案