video capturing works in the example code, but doesn't in my own project












1















I built opencv with openni2 using Cmake, and I succeeded to run the example 'openni_capture' which is in OpenCV.sln. It clearly shows the video being captured. I'm using Orbbec Astra camera.



But when I try to make my own project, copy and paste the code, and run it, it says 'can not open a capture object' even if it was successfully built.



The code is like below. The problem is that 'capture.isOpened()' is TRUE in the example project, but it is FALSE in my own project which has exactly same code as the example project.



#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;
}
.
.
.


I added to VC++ directory-include directory that



C:OpenCV_endSourceopencv-3.4.0buildinstallinclude ,C:Program FilesOpenNI2Include



I added to VC++ directory-library directory that



C:OpenCV_endSourceopencv-3.4.0buildinstallx64vc14lib ,C:Program FilesOpenNI2Lib



I added to Linker-input that



opencv_world340d.lib ,OpenNI2.lib



and I copied the dll files to the folder which contains my project source. opencv_world340d.dll and all the files which are in C:Program FilesOpenNI2Redist



but it never wants to work.. Please help me



Thank you.










share|improve this question

























  • Hi, what does capture.open returns? Should be boolean, but you don't test that value.

    – Aif
    Jan 20 at 12:24











  • have a look at the sample project's project-settings and make sure you aren't missing something.

    – Micka
    Jan 20 at 12:50











  • are you compiling with debug or with release version of msvc libraries?

    – Micka
    Jan 20 at 12:51











  • @Aif Hi, capture.open(CAP_OPENNI2) is TRUE in the example project, but capture.open(CAP_OPENNI2), capture.open(CAP_OPENNI) are both FALSE in my own project. Must be something wrong in my project setting, but I cannot find.

    – 이건도
    Jan 21 at 1:49











  • @Micka I'm compiling with debug. I wrote my project settings. should I add something?

    – 이건도
    Jan 21 at 1:51
















1















I built opencv with openni2 using Cmake, and I succeeded to run the example 'openni_capture' which is in OpenCV.sln. It clearly shows the video being captured. I'm using Orbbec Astra camera.



But when I try to make my own project, copy and paste the code, and run it, it says 'can not open a capture object' even if it was successfully built.



The code is like below. The problem is that 'capture.isOpened()' is TRUE in the example project, but it is FALSE in my own project which has exactly same code as the example project.



#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;
}
.
.
.


I added to VC++ directory-include directory that



C:OpenCV_endSourceopencv-3.4.0buildinstallinclude ,C:Program FilesOpenNI2Include



I added to VC++ directory-library directory that



C:OpenCV_endSourceopencv-3.4.0buildinstallx64vc14lib ,C:Program FilesOpenNI2Lib



I added to Linker-input that



opencv_world340d.lib ,OpenNI2.lib



and I copied the dll files to the folder which contains my project source. opencv_world340d.dll and all the files which are in C:Program FilesOpenNI2Redist



but it never wants to work.. Please help me



Thank you.










share|improve this question

























  • Hi, what does capture.open returns? Should be boolean, but you don't test that value.

    – Aif
    Jan 20 at 12:24











  • have a look at the sample project's project-settings and make sure you aren't missing something.

    – Micka
    Jan 20 at 12:50











  • are you compiling with debug or with release version of msvc libraries?

    – Micka
    Jan 20 at 12:51











  • @Aif Hi, capture.open(CAP_OPENNI2) is TRUE in the example project, but capture.open(CAP_OPENNI2), capture.open(CAP_OPENNI) are both FALSE in my own project. Must be something wrong in my project setting, but I cannot find.

    – 이건도
    Jan 21 at 1:49











  • @Micka I'm compiling with debug. I wrote my project settings. should I add something?

    – 이건도
    Jan 21 at 1:51














1












1








1








I built opencv with openni2 using Cmake, and I succeeded to run the example 'openni_capture' which is in OpenCV.sln. It clearly shows the video being captured. I'm using Orbbec Astra camera.



But when I try to make my own project, copy and paste the code, and run it, it says 'can not open a capture object' even if it was successfully built.



The code is like below. The problem is that 'capture.isOpened()' is TRUE in the example project, but it is FALSE in my own project which has exactly same code as the example project.



#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;
}
.
.
.


I added to VC++ directory-include directory that



C:OpenCV_endSourceopencv-3.4.0buildinstallinclude ,C:Program FilesOpenNI2Include



I added to VC++ directory-library directory that



C:OpenCV_endSourceopencv-3.4.0buildinstallx64vc14lib ,C:Program FilesOpenNI2Lib



I added to Linker-input that



opencv_world340d.lib ,OpenNI2.lib



and I copied the dll files to the folder which contains my project source. opencv_world340d.dll and all the files which are in C:Program FilesOpenNI2Redist



but it never wants to work.. Please help me



Thank you.










share|improve this question
















I built opencv with openni2 using Cmake, and I succeeded to run the example 'openni_capture' which is in OpenCV.sln. It clearly shows the video being captured. I'm using Orbbec Astra camera.



But when I try to make my own project, copy and paste the code, and run it, it says 'can not open a capture object' even if it was successfully built.



The code is like below. The problem is that 'capture.isOpened()' is TRUE in the example project, but it is FALSE in my own project which has exactly same code as the example project.



#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;
}
.
.
.


I added to VC++ directory-include directory that



C:OpenCV_endSourceopencv-3.4.0buildinstallinclude ,C:Program FilesOpenNI2Include



I added to VC++ directory-library directory that



C:OpenCV_endSourceopencv-3.4.0buildinstallx64vc14lib ,C:Program FilesOpenNI2Lib



I added to Linker-input that



opencv_world340d.lib ,OpenNI2.lib



and I copied the dll files to the folder which contains my project source. opencv_world340d.dll and all the files which are in C:Program FilesOpenNI2Redist



but it never wants to work.. Please help me



Thank you.







opencv openni orbbec






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 21 at 2:55







이건도

















asked Jan 20 at 12:14









이건도이건도

62




62













  • Hi, what does capture.open returns? Should be boolean, but you don't test that value.

    – Aif
    Jan 20 at 12:24











  • have a look at the sample project's project-settings and make sure you aren't missing something.

    – Micka
    Jan 20 at 12:50











  • are you compiling with debug or with release version of msvc libraries?

    – Micka
    Jan 20 at 12:51











  • @Aif Hi, capture.open(CAP_OPENNI2) is TRUE in the example project, but capture.open(CAP_OPENNI2), capture.open(CAP_OPENNI) are both FALSE in my own project. Must be something wrong in my project setting, but I cannot find.

    – 이건도
    Jan 21 at 1:49











  • @Micka I'm compiling with debug. I wrote my project settings. should I add something?

    – 이건도
    Jan 21 at 1:51



















  • Hi, what does capture.open returns? Should be boolean, but you don't test that value.

    – Aif
    Jan 20 at 12:24











  • have a look at the sample project's project-settings and make sure you aren't missing something.

    – Micka
    Jan 20 at 12:50











  • are you compiling with debug or with release version of msvc libraries?

    – Micka
    Jan 20 at 12:51











  • @Aif Hi, capture.open(CAP_OPENNI2) is TRUE in the example project, but capture.open(CAP_OPENNI2), capture.open(CAP_OPENNI) are both FALSE in my own project. Must be something wrong in my project setting, but I cannot find.

    – 이건도
    Jan 21 at 1:49











  • @Micka I'm compiling with debug. I wrote my project settings. should I add something?

    – 이건도
    Jan 21 at 1:51

















Hi, what does capture.open returns? Should be boolean, but you don't test that value.

– Aif
Jan 20 at 12:24





Hi, what does capture.open returns? Should be boolean, but you don't test that value.

– Aif
Jan 20 at 12:24













have a look at the sample project's project-settings and make sure you aren't missing something.

– Micka
Jan 20 at 12:50





have a look at the sample project's project-settings and make sure you aren't missing something.

– Micka
Jan 20 at 12:50













are you compiling with debug or with release version of msvc libraries?

– Micka
Jan 20 at 12:51





are you compiling with debug or with release version of msvc libraries?

– Micka
Jan 20 at 12:51













@Aif Hi, capture.open(CAP_OPENNI2) is TRUE in the example project, but capture.open(CAP_OPENNI2), capture.open(CAP_OPENNI) are both FALSE in my own project. Must be something wrong in my project setting, but I cannot find.

– 이건도
Jan 21 at 1:49





@Aif Hi, capture.open(CAP_OPENNI2) is TRUE in the example project, but capture.open(CAP_OPENNI2), capture.open(CAP_OPENNI) are both FALSE in my own project. Must be something wrong in my project setting, but I cannot find.

– 이건도
Jan 21 at 1:49













@Micka I'm compiling with debug. I wrote my project settings. should I add something?

– 이건도
Jan 21 at 1:51





@Micka I'm compiling with debug. I wrote my project settings. should I add something?

– 이건도
Jan 21 at 1:51












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54276313%2fvideo-capturing-works-in-the-example-code-but-doesnt-in-my-own-project%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54276313%2fvideo-capturing-works-in-the-example-code-but-doesnt-in-my-own-project%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Liquibase includeAll doesn't find base path

How to use setInterval in EJS file?

Petrus Granier-Deferre