im working with windows 10, opencv 3.0, and visual studio 2012. im trying to use bgslibrary example code. When I try to build the bgslibrary I get the following error C2864
#include <iostream>'
#include <cv.h>'
#include <highgui.h>
#include "package_bgs\bgslibrary.h"
#include "package_bgs\FrameDifference.h"
int main(int argc, char **argv)
{
CvCapture *capture = 0;
capture = cvCaptureFromCAM(0);
if(!capture){
std::cerr << "Cannot initialize video!" << std::endl;
return -1;
}
IBGS *bgs;
bgs = new FrameDifference;
IplImage *frame;
while(1)
{
frame = cvQueryFrame(capture);
if(!frame) break;
cv::Mat img_input = cv::cvarrToMat(frame);
cv::imshow("Input", img_input);
cv::Mat img_mask;
cv::Mat img_bkgmodel;
// by default, it shows automatically the foreground mask image
bgs->process(img_input, img_mask, img_bkgmodel);
//if(!img_mask.empty())
// cv::imshow("Foreground", img_mask);
// do something
if(cvWaitKey(33) >= 0)
break;
}
delete bgs;
cvDestroyAllWindows();
cvReleaseCapture(&capture);
return 0;
}
1 error C2864: 'bgslibrary::algorithms::IBGS::firstTime' : only static const integral data members can be initialized within a class
2 error C2864: 'bgslibrary::algorithms::IBGS::showOutput' : only static const integral data members can be initialized within a class
5 error C2864: 'bgslibrary::algorithms::IBGS::firstTime' : only static const integral data members can be initialized within a class
16 IntelliSense: data member initializer is not allowed c:\Users\izzaa\Documents\Visual Studio 2012\Projects\Project1_bgslibrary\Project1_bgslibrary\package_bgs\CodeBook.h 48
17 IntelliSense: data member initializer is not allowed c:\Users\izzaa\Documents\Visual Studio 2012\Projects\Project1_bgslibrary\Project1_bgslibrary\package_bgs\CodeBook.h 49
Related
As I am completely new to OpenCV, I tried following a tutorial to capture video from a webcam. I used the following code:
#include "opencv2\opencv.hpp"
#include <stdint.h>
using namespace cv;
using namespace std;
int main(int argv, char** argc) {
Mat frame;
VideoCapture vid(0); //0 if we only have one camera
if (!vid.isOpened()) { //check camera has been initialized
cout << "ERROR: Cannot open the camera";
return -1;
}
while (vid.read(frame)) {
imshow("webcam", frame);
if (waitKey(30) >= 0) break;
}
return 0;
}
When I run the program, a window that shows the video feed opens, but it then almost immediately closes. I get this snippet from the Debug output:
SETUP: Device is setup and ready to capture.
Event: Code: 0x0d Params: 0, 0
Event: Code: 0x0e Params: 0, 0
Exception thrown at 0x000007FEFCBAA06D in test.exe: Microsoft C++ exception: cv::Exception at memory location 0x000000000026EB10.
SETUP: Disconnecting device 0
I don't know what could be wrong with my code or even how to begin debugging this. Any advice? Thank you!
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 have been using openCv for a while, but have just moved to windows 10.
Now, existing applications will compile, but I cannot make a new one.
In a new project (visual studio 2015, release 64)
I am adding all the libs:
opencv_calib3d310.lib
opencv_core310.lib
opencv_features2d310.lib
opencv_flann310.lib
opencv_highgui310.lib
opencv_imgcodecs310.lib
opencv_imgproc310.lib
opencv_ml310.lib
opencv_objdetect310.lib
opencv_photo310.lib
opencv_shape310.lib
opencv_stitching310.lib
opencv_superres310.lib
opencv_ts310.lib
opencv_video310.lib
opencv_videoio310.lib
opencv_videostab310.lib
setting:
D:\opencv-master\build64\lib\Release;%(AdditionalLibraryDirectories)
and
D:\opencv-master\modules\highgui\include
D:\opencv-master\modules\imgcodecs\include
D:\opencv-master\modules\core\include
D:\opencv-master\modules\videoio\include
D:\opencv-master\modules\imgproc\include
%(AdditionalIncludeDirectories)
and adding the most basic:
#include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include "stdafx.h"
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, char** argv)
{
if (argc != 2)
{
cout << " Usage: display_image ImageToLoadAndDisplay" << endl;
return -1;
}
Mat image;
image = imread(argv[1], IMREAD_COLOR); // Read the file
if (image.empty()) // Check for invalid input
{
cout << "Could not open or find the image" << std::endl;
return -1;
}
namedWindow("Display window", WINDOW_AUTOSIZE); // Create a window for display.
imshow("Display window", image); // Show our image inside it.
waitKey(0); // Wait for a keystroke in the window
return 0;
}
In visual studio, Intellisense is fine, no red underlines, everything looks good. When I try to compile tho...
'cv': a namespace with this name does not exist
'Mat': undeclared identifier
'image': undeclared identifier
...and many more. It is like it cannot find the libs, but i am linking them correctly, I am sure of it.
Can anyone assist me here?
I have a problem : error LNK2019: unresolved external symbol [...] referenced in function main
#include <opencv2/highgui/highgui.hpp>
using namespace std;
using namespace cv;
int main(int argc, char * const argv[])
{
cvNamedWindow("P2", CV_WINDOW_AUTOSIZE);
//path to image ex : c:/Users/image.jpg
CvCapture* capture = cvCreateFileCapture("path to image");
IplImage* frame;
while (1) {
frame = cvQueryFrame(capture);
if (!frame) break; cvShowImage("P2", frame); char c = cvWaitKey(0); if (c == 27) break;
}
cvReleaseCapture(&capture); cvDestroyWindow("P2");
return 0;
}
enter image description here
I start my project by following tutorial, the same configuration to use OpenCV with visual Studio and Eclipse but I have the same error.
Probably you're missing to specify input library (project property/link/input).
You don't specify which version of opencv you are using. If you are using openCV 3.1 like me the lib is opencv_world310d.lib for debug and opencv_world310.lib for release. Please check also the bitness of your application. The prebuilt libraries are for 64 bit.
So I have played around in OpenCV a bunch before and never run into this problem. I am implementing a MeanShift algorithm and trying to do it on video devices, images, and videos. Devices and images work; however, no matter what I try, when I run VideoCapture on my filename (whether setting it in the Constructor or using the VideoCapture::open() method, and whether local or with a full path) I always get stuck in my error check.
Thoughts? Ideas? code below. running in Visual Studio 2012
#include "opencv2\highgui\highgui.hpp"
#include "opencv2\core\core.hpp"
#include "opencv2\opencv.hpp"
#include "opencv2\video\video.hpp"
#include <string>
using cv::Mat;
using std::string;
enum Filetype{Image, Video};
int main(int argc, char* argv[])
{
string filename = "short_front.avi";// "C:\\Users\\Jonathan\\Videos\\short_front.mp4"; //"hallways.jpg";
Mat cv_image; //convert to unsigned char * with data
Mat filtImage_;
Mat segmImage_;
Mat whiteImage_;
cv::VideoCapture vid;
vid.open("C:/Users/Jonathan/Desktop/TestMeanShift/TestMeanShift/short_front.avi");
cv::waitKey(1000);
if ( !vid.isOpened() ){
throw "Error when reading vid";
cv::waitKey(0);
return -1;
}
// cv_image = cv::imread(filename);//, CV_LOAD_IMAGE_COLOR);
// if(! cv_image.data){
// std::cerr << "Image Failure: " << std::endl;
// system("pause");
// return -1;
// }
//Mat cv_image_gray;
//cv::cvtColor(cv_image,cv_image_gray,CV_RGB2GRAY);
for (;;)
{
vid >> cv_image;
if ( !cv_image.data)
continue;
cv::imshow("Input",cv_image); //add a normal window here to resizable
}
EDIT: This is a distinct problem from the one listed here because it deals with a specific corner case: VideoCapture and ImageCapture both work, only not VideoCapture with a file. When it doesn't work, the code runs properly, except that the "video" it creates is incomplete as it didn't open properly. Therefore, as the code above does not crash in compile time or run time, the only indicator is bad output (6KB video output file). If you are having issues not with the corner case I am describing but general issues with the above functions in OpenCV, the aforementioned link could help you.