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"
Related
I build OpenCV 3.4 with Gstreamer MSVC 1.16.1, using Cmake and Visual Studio 10.
I have include bin directory to the system path variable, added all additional include and library to Visual Studio.
Now when I am trying to read an Image to test if OpenCV is correctly installed it throws an error as:
OpenCV Error: Assertion failed (size.width>0 && size.height>0) in imshow, file .../opencv/modules/highgui/src/window.cpp
The code was:
Mat image1;
image1 = imread("D:\\Capture2.JPG");
if(! image1.data ) // Check for invalid input
{
cout << "Could not open or find the image" << std::endl ;
}
imshow("Image",image1);
cvWaitKey(0);
return 0;
Now I tried to play a video using demo code from openCV site:
// opencv_3.4_test.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "opencv2/opencv.hpp"
#include <iostream>
using namespace std;
using namespace cv;
int _tmain(int argc, _TCHAR* argv[])
{
// Create a VideoCapture object and open the input file
// If the input is the web camera, pass 0 instead of the video file name
VideoCapture cap("Wildlife.mp4");
// Check if camera opened successfully
if(!cap.isOpened()){
cout << "Error opening video stream or file" << endl;
return -1;
}
while(1){
Mat frame;
// Capture frame-by-frame
cap >> frame;
// If the frame is empty, break immediately
if (frame.empty())
break;
// Display the resulting frame
imshow( "Frame", frame );
// Press ESC on keyboard to exit
char c=(char)waitKey(25);
if(c==27)
break;
}
// When everything done, release the video capture object
cap.release();
// Closes all the frames
destroyAllWindows();
return 0;
}
The program is building correctly but I am getting following error while running it:
warning: Error opening file (/build/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:808)
warning: ?Wildlife.mp4 (/build/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:809)
GStreamer: error opening bin syntax error
Where can be the error as they both are simplest OpenCV program.
So the error was, there was an invisible character ('\u202A') present just after " of the filename. Once I deleted it, everything runs fine.
I found this from the warning C4566: character represented by universal-character-name '\u202A' cannot be represented in the current code page (1252)
I have install opencv in ubuntu 18.04 and it was installed successfully, I have tried this command:
$ pkg-config --modversion opencv
and its output is: 4.0.1-dev
after this i have tried to rum c++ code:
#include <opencv2/highgui.hpp>
#include <iostream>
using namespace std;
int main( int argc, char** argv ) {
cv::Mat image;
image = cv::imread("sample.jpeg" , CV_LOAD_IMAGE_COLOR);
if(! image.data ) {
std::cout << "Could not open or find the image" << std::endl ;
return -1;
}
cv::namedWindow( "Display window", cv::WINDOW_AUTOSIZE );
cv::imshow( "Display window", image );
cv::waitKey(0);
return 0;
}
with this command: :~/cpp_test$ g++ main.cpp -o output pkg-config --cflags --libs opencv
but it throws a fatal error:
main.cpp:1:10: fatal error: opencv2/highgui.hpp: No such file or directory
#include <opencv2/highgui.hpp>
^~~~~~~~~~~~~~~~~~~~~
compilation terminated.
I have reviewed some similar questions but i did not find my answer, i think this is because of environment variables and i do not know which variables i have to set.
In the compiling command add a "4" next to "opencv" (or the number of your version of OpenCV):
$ g++ main.cpp -o output \`pkg-config --cflags --libs opencv4\`
I am compiling on Ubuntu 14.04 using OpenCV 3.1. When trying to open a video file it gives this error:
"Cannot open the video file"
I installed everything i could install : ffmpeg etc. Haven't found a solution checking out similar questions on StackOF.
What do ?
cv::VideoCapture cap(argv[1]);
Where argv[1] is the file name in the same directory as the executable.
In case your constructor is failing, you may want to use the .open() method. So, if you want to open a file that is called "myVideo.mp4" that is in the folder of your project, you would do the following:
cv::VideoCapture cap;
cap.open("myVideo.mp4");
For more detailed informations about this method, check this documentation link
Also, the book Learning OpenCV 3, from the O'Rilley media, on page 26 gives you a good example. Here is a Gist that I made to give you as an example.
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
int main() {
cv::VideoCapture cap;
cap.open("myVideo.mp4" );
cv::namedWindow( "myVideo", cv::WINDOW_AUTOSIZE );
cv::Mat frame;
while(true) {
cap >> frame;
if( frame.empty() ){
std::cout << "Could not load the video frames. \n";
break;
}
cv::imshow( "myVideo", frame );
if( cv::waitKey(27) >= 0 ){
std::cout << "Escape pressed \n";
break;
}
}
return 0;
}
I installed OpenCV to Ubuntu 14.04. I'm trying to fallow tutorials at opencv website. I got an error while running this code. I'm using eclipse
to run the code. I'm getting this error while building project.
I added, opencv_core, opencv_highgui,opencv_imgcodecs libraries to g++ linker.
Error message:
//usr/local/lib/libopencv_imgproc.so.3.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make: *** [optest01] Error 1
Code :
#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
#include <stdlib.h>
#include <stdio.h>
using namespace cv;
/// Global variables
Mat src, src_gray;
Mat dst, detected_edges;
/** #function main */
int main( int argc, char** argv )
{
/// Load an image
src = imread( "/images/Lenna.jpg" );
if( !src.data )
{ return -1; }
/// Create a matrix of the same type and size as src (for dst)
dst.create( src.size(), src.type() );
/// Convert the image to grayscale
cvtColor( src, src_gray, COLOR_BGR2GRAY );
return 0;
}
Your error code:
//usr/local/lib/libopencv_imgproc.so.3.0: error adding symbols: DSO missing from command line
is telling you that you haven't linked opencv_imgproc.
Just link the required library:
-lopencv_imgproc
I had the similar problem DSO missing from command line and adding the -L/usr/local/libin front solved the problem for me i.e. g++ source_code.cpp -o output_name -L/usr/local/lib <dependent libraries e.g. -lopencv_highgui>
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.)