I am trying to develop a stereoscopic vision system. I am receiving the messages below whenever I try to build my code:
***** Build of configuration Debug for project RicoCameraCpp ****
make all
Building file: ../main.cpp
Invoking: Cross G++ Compiler
g++ -I/home/ux/Downloads -I/usr/local/boost_1_52_0/boost -I/usr/local/boost_1_52_0 - I/home/ux/Downloads/opencv2 -include/home/ux/Downloads/opencv2/opencv_modules.hpp -include/usr/local/boost_1_52_0/boost/thread.hpp -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"main.d" -MT"main.d" -o "main.o" "../main.cpp"
In file included from /usr/local/boost_1_52_0/boost/thread/thread.hpp:22:0,
from /usr/local/boost_1_52_0/boost/thread.hpp:13,
from <command-line>:0:
/usr/local/boost_1_52_0/boost/thread/detail/thread.hpp: In member function ‘void boost::detail::thread_data<F>::run() [with F = int (*)(int, char**)]’:
../main.cpp:81:1: instantiated from here
/usr/local/boost_1_52_0/boost/thread/detail/thread.hpp:78:17: error: too few arguments to function
/usr/local/boost_1_52_0/boost/system/error_code.hpp: At global scope:
/usr/local/boost_1_52_0/boost/system/error_code.hpp:214:36: warning: ‘boost::system::posix_category’ defined but not used [-Wunused-variable]
/usr/local/boost_1_52_0/boost/system/error_code.hpp:215:36: warning: ‘boost::system::errno_ecat’ defined but not used [-Wunused-variable]
/usr/local/boost_1_52_0/boost/system/error_code.hpp:216:36: warning: ‘boost::system::native_ecat’ defined but not used [-Wunused-variable]
make: *** [main.o] Error 1
**** Build Finished *****
Here's my code:
#include "cstdlib"
#include "cmath"
#include "opencv/cv.h"
#include "opencv/highgui.h"
#include "boost/thread.hpp"
#include <iostream>
using namespace std;
using namespace boost;
using namespace cv;
int firstCam( int argc, char** argv )
{
//initilize first camera
CvCapture* captureRightCam = cvCaptureFromCAM(0);
//check if first camera is available
if(!captureRightCam)
{
cout << "No first camera to capture\n";
return(-1);
}
//create right window
cvNamedWindow( "Right Cam", CV_WINDOW_AUTOSIZE );
//display frames for every cvWaitKey duration
while ( 1 )
{
//get frames
IplImage* rightFrame = cvQueryFrame( captureRightCam );
//check if captured
if ( !rightFrame )
{
fprintf( stderr, "ERROR: frame is null...\n" );
getchar();
break;
}
//show frames inside the windows
cvShowImage( "Right Cam", rightFrame );
cvWaitKey(150);
}
//release and destroy windows
cvReleaseCapture( &captureRightCam );
cvDestroyWindow( "Right Cam" );
return 0;
}
int secondCam( int argc, char** argv )
{
CvCapture* captureLeftCam = cvCaptureFromCAM(1);
if(!captureLeftCam)
{
cout << "No second camera to capture\n";
return(-1);
}
cvNamedWindow( "Left Cam", CV_WINDOW_AUTOSIZE );
while ( 1 )
{
IplImage* leftFrame = cvQueryFrame( captureLeftCam );
if ( !leftFrame )
{
fprintf( stderr, "ERROR: frame is null...\n" );
getchar();
break;
}
cvShowImage( "Left Cam", leftFrame );
cvWaitKey(150);
}
cvReleaseCapture( &captureLeftCam );
cvDestroyWindow( "Left Cam" );
return 0;
}
int main()
{
boost::thread t1(firstCam);
boost::thread t2(secondCam);
return 0;
}
What am I doing wrong?
I think the error message is very descriptive, actually:
You are trying to make a thread out of your function firstCam. That function takes two arguments, but when you create your thread, you don't give it any arguments. It therefore can't figure out what arguments to pass to your function and therefore complains about "too few arguments".
In this case, it seems that you copied the function signatures from somewhere without giving it any thought. You never use argc and argv at all.
(As a side note:
using namespace std;
using namespace boost;
using namespace cv;
is a bad idea and will get you into trouble sooner or later. See GotW 53 for details.)
Related
I'm working on a project where tracking objects is involved, and I'm trying to get OpenCV contrib repo's TrackerKCF to work. This is the sample code that I got online:
#include <opencv2/core/utility.hpp>
#include <opencv2/video/tracking.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/highgui.hpp>
#include <iostream>
#include <cstring>
using namespace std;
using namespace cv;
int main( int argc, char** argv ){
// show help
if(argc<2){
cout<<
" Usage: example_tracking_kcf <video_name>\n"
" examples:\n"
" example_tracking_kcf Bolt/img/%04.jpg\n"
" example_tracking_kcf faceocc2.webm\n"
<< endl;
return 0;
}
// create the tracker
Ptr<Tracker> tracker = TrackerKCF::create();
// set input video
std::string video = argv[1];
VideoCapture cap(video);
Mat frame;
// get bounding box
cap >> frame;
Rect2d roi= selectROI("tracker", frame, true, false);
//quit if ROI was not selected
if(roi.width==0 || roi.height==0)
return 0;
// initialize the tracker
tracker->init(frame,roi);
// do the tracking
printf("Start the tracking process, press ESC to quit.\n");
for ( ;; ){
// get frame from the video
cap >> frame;
// stop the program if no more images
if(frame.rows==0 || frame.cols==0)
break;
// update the tracking result
bool isfound = tracker->update(frame,roi);
if(!isfound)
{
cout << "The target has been lost...\n";
waitKey(0);
return 0;
}
// draw the tracked object
rectangle( frame, roi, Scalar( 255, 0, 0 ), 2, 1 );
// show image with the tracked object
imshow("tracker",frame);
//quit on ESC button
if(waitKey(1)==27)break;
}
}
However, I got the following error:
tracktest.cpp: In function ‘int main(int, char**)’:
tracktest.cpp:33:7: error: ‘Tracker’ was not declared in this scope
Ptr<Tracker> tracker = TrackerKCF::create();
^
tracktest.cpp:33:14: error: template argument 1 is invalid
Ptr<Tracker> tracker = TrackerKCF::create();
^
tracktest.cpp:33:26: error: ‘TrackerKCF’ has not been declared
Ptr<Tracker> tracker = TrackerKCF::create();
^
tracktest.cpp:43:54: error: ‘selectROI’ was not declared in this scope
Rect2d roi= selectROI("tracker", frame, true, false);
^
tracktest.cpp:50:10: error: base operand of ‘->’ is not a pointer
tracker->init(frame,roi);
^
tracktest.cpp:63:27: error: base operand of ‘->’ is not a pointer
bool isfound = tracker->update(frame,roi);
^
./tracktest.sh: line 5: ./tracktest: No such file or directory
I tried to reinstall OpenCV 3.1.0 and the corresponding contrib repo, and it seemed thatmake completed just fine. I also tried to locate where tracker.cpp is in my OpenCV source directory, but nothing popped up.
I assume that it's because I've incorrectly installed the contrib modules, but I'm not sure. Can anyone figure out what's wrong? Thanks in advance.
Due to my inexplicable stupidity I forgot to run make install.
It's all good now!
I write simple application and have problem with raspicam library. I've opened simpletest_raspicamm.cpp:
#include <ctime>
#include <fstream>
#include <iostream>
#include <raspicam/raspicam.h>
using namespace std;
int main ( int argc,char **argv ) {
raspicam::RaspiCam Camera; //Cmaera object
//Open camera
cout<<"Opening Camera..."<<endl;
if ( !Camera.open()) {cerr<<"Error opening camera"<<endl;return -1;}
//wait a while until camera stabilizes
cout<<"Sleeping for 3 secs"<<endl;
//capture
Camera.grab();
//allocate memory
unsigned char *data=new unsigned char[ Camera.getImageTypeSize ( raspicam::RASPICAM_FORMAT_RGB )];
//extract the image in rgb format
Camera.retrieve ( data,raspicam::RASPICAM_FORMAT_RGB );//get camera image
//save
std::ofstream outFile ( "raspicam_image.ppm",std::ios::binary );
outFile<<"P6\n"<<Camera.getWidth() <<" "<<Camera.getHeight() <<" 255\n";
outFile.write ( ( char* ) data, Camera.getImageTypeSize ( raspicam::RASPICAM_FORMAT_RGB ) );
cout<<"Image saved at raspicam_image.ppm"<<endl;
//free resrources
delete data;
return 0;
}
And console returns me cout:
/home/pi/Desktop/raspicam-0.0.7/src/private/private_impl.cpp:171 :Private_Impl::retrieve type is not RASPICAM_FORMAT_IGNORE as it should be
Image saved at raspicam_image.ppm
I use raspicam 0.0.7 i tried to use every other version and nothings changes. I compile use command:
g++ -ggdb -o `basename server.cpp .cpp` server1.cpp -I/usr/local/include/ - lraspicam -L/opt/vc/lib
I've tried to use Camera.setFormat(raspicam::RASPICAM_FORMAT_IGNORE) and have no idea how to fix it. I work on raspberry pi 2, but on rpi3 everything works fine.
It appears that the interface of retrieve() has been changed since v0.0.5 according to the comments in the header file.
Basically the parameter is useless now, and can be always set to RASPICAM_FORMAT_IGNORE, or just left blank for the C++ default parameter to kick in. The warning you're seeing basically does nothing and won't have any impact on the performance.
Format can now be set by an independent function
void setFormat ( RASPICAM_FORMAT fmt );
I copy this code from openCV2 book and this code have argc and argv as arguments that I don't know what they are and why assign to 1 (argc=1) and terminate debugging ...my problem that why argc=1? And how I can fix it? because my argc should be 2 (argc==2)...
#include <stdio.h>
#include <opencv2/opencv.hpp>
using namespace cv;
int main( int argc, char** argv )
{
if ( argc ! = 2 )
{
printf( " usage: DisplayImage.out <Image_Path>\n" );
return - 1;
}
Mat image;
image = imread( argv[ 1], 1 );
if ( ! image.data )
{
printf( " No image data \n" );
return - 1;
}
namedWindow( " Display Image" , WINDOW_AUTOSIZE );
imshow( " Display Image" , image);
waitKey( 0);
return 0;
}
I try to wrote this code without argc and argv but the debugger has a runtime error that i think its cause be argc.
If you run it by command line, you can call it as
DisplayImage "path_to_image"
If you want to run from VS, be sure to add the "path_to_image" in your command arguments:
PROJECT -> Properties -> Configuration Properties -> Debugging
Put the "path_to_image" in Command Arguments
Be sure that "path_to_image" is a valid path, check here for reference.
As already pointed out in comments, it's a very bad example!
OpenCV 3.0.0 has also CommandLineParser for more complex input arguments.
I am using openCV for the first time, I have followed the installation guide(for linux with eclipse CDT) and trying to run the sample program, but I keep getting the following error message.
terminate called after throwing an instance of 'std::logic_error'
what(): basic_string::_S_construct null not valid
#include<cv.h>
#include<highgui.h>
using namespace cv;
int main( int argc, char** argv ){
Mat image;
image = imread( argv[1], 1 );
if( argc != 2 || !image.data )
{
printf( "No image data \n" );
return -1;
}
namedWindow( "Display Image", CV_WINDOW_AUTOSIZE );
imshow( "Display Image", image );
waitKey(0);
return 0;
}
I got this same problem after finally getting my OpenCV libraries to link. You are probably running the executable without an argument resulting in argv[1] to be Null when you try and do an image read. The solution for me, on eclipse, was to call the file directly with an argument in command prompt; "testOpenCV.exe imageFile.png". I obviously was using windows, but simply calling the executable with an argument, in terminal for your linux, should work.
I am trying to use this sample code to read a video file but everytime I compile I get these errors.
Here's the code:
#include "cv.h"
#include "highgui.h"
int main(int argc, char** argv)
{
CvCapture* capture=0;
IplImage* frame=0;
capture = cvCaptureFromAVI("~/Documents/OpenCV/OpenCV-2.4.2/samples/c/tree.avi"); // read AVI video
if( !capture )
throw "Error when reading steam_avi";
cvNamedWindow( "w", 1);
for( ; ; )
{
/* int cvGrabFrame (CvCapture* capture);
IplImage* cvRetrieveFrame (CvCapture* capture)*/
frame = cvQueryFrame( capture );
if(!frame)
break;
cvShowImage("w", frame);
}
cvWaitKey(0); // key press to close window
cvDestroyWindow("w");
cvReleaseCapture(&capture);
Here is what I compiled with:
g++ CaptureVideo.cpp -o CaptureVideo \-I /usr/local/include/opencv -L /usr/local/lib \-lm -lcv -lhighgui -lcvaux
I am using Ubuntu 12.04. I get these errors when I compile
"/usr/bin/ld: cannot find -lcv"
"/usr/bin/ld: cannot find -lhighgui"
"/usr/bin/ld: cannot find -lcvaux"
"collect2: ld returned 1 exit status"