захват видео работает в примере кода, но не в моем собственном проекте - PullRequest
0 голосов
/ 20 января 2019

Я собрал opencv с openni2, используя Cmake, и мне удалось запустить пример ' openni_capture ', который находится в OpenCV.sln .Это ясно показывает, что видео было захвачено.Я использую Orbbec Astra камеру.

Но когда я пытаюсь создать свой собственный проект, скопировать и вставить код и запустить его, он говорит: « не может открытьзахватить объект ', даже если он был успешно построен.

Код подобен приведенному ниже.Проблема в том, что ' capture.isOpened () ' является ИСТИНОЙ в примере проекта, но в моем собственном проекте это ЛОЖЬ, код которой точно такой же, как и в примере проекта.

#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

, но он никогда не хочет работать .. Пожалуйста, помогите мне

Спасибо.

...