OpenCV 3 error 'CV_FOURCC': identifier not found - c++

Just built OpenCV 3 on PC with Visual Studio 2013 and now I'm trying code but sadly I can't figure out what's wrong?
#include "opencv2/opencv.hpp"
#include <iostream>
using namespace std;
using namespace cv;
int main() {
VideoCapture vcap(0);
if (!vcap.isOpened()) {
cout << "Error opening video stream or file" << endl;
return -1;
}
int frame_width = vcap.get(cv::CAP_PROP_FRAME_WIDTH);
int frame_height = vcap.get(cv::CAP_PROP_FRAME_HEIGHT);
VideoWriter video("out.avi", CV_FOURCC('M', 'J', 'P', 'G'), 10, Size(frame_width, frame_height), true);
for (;;) {
Mat frame;
vcap >> frame;
video.write(frame);
imshow("Frame", frame);
char c = (char)waitKey(33);
if (c == 27) break;
}
return 0;
1>------ Build started: Project: ConsoleApplication12, Configuration: Release x64 ------
1> Source.cpp
1>Source.cpp(21): warning C4244: 'initializing' : conversion from 'double' to 'int', possible loss of data
1>Source.cpp(22): warning C4244: 'initializing' : conversion from 'double' to 'int', possible loss of data
1>Source.cpp(23): error C3861: 'CV_FOURCC': identifier not found
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Couldn't figure out with what I have to replace "CV_FOURCC".
edited:
int frame_width = vcap.get(cv::CAP_PROP_FRAME_WIDTH);
int frame_height = vcap.get(cv::CAP_PROP_FRAME_HEIGHT);
int codec = cv::VideoWriter::fourcc('M', 'J', 'P', 'G');
VideoWriter video("out.avi", codec, 10, Size(frame_width, frame_height), true);

looks like this has changed in later versions of OpenCV to cv::VideoWriter::fourcc(...) where ... is the four-character-comma-separated list.
More information here for OpenCV 3.4: https://docs.opencv.org/3.4/dd/d9e/classcv_1_1VideoWriter.html#afec93f94dc6c0b3e28f4dd153bc5a7f0

I used bad OpenCV source to build my libraries.

Related

Aruco Marker Generating Visual studio 2019 vc16

I am trying to generate aruco marker using Visual Studio vc16 and opencv 4.70 lib with opencv_contrib.4. After building the libraries, i tried to run a short simple program for generating aruco marker and I got an error that I added after code.
the code that I am using:
#include <opencv2/highgui.hpp>
#include <opencv2/aruco.hpp>
using namespace cv;
namespace {
const char* about = "Create an ArUco marker image";
const char* keys =
"{#outfile |<none> | Output image }"
"{d | | dictionary: DICT_4X4_50=0, DICT_4X4_100=1, DICT_4X4_250=2,"
"DICT_4X4_1000=3, DICT_5X5_50=4, DICT_5X5_100=5, DICT_5X5_250=6, DICT_5X5_1000=7, "
"DICT_6X6_50=8, DICT_6X6_100=9, DICT_6X6_250=10, DICT_6X6_1000=11, DICT_7X7_50=12,"
"DICT_7X7_100=13, DICT_7X7_250=14, DICT_7X7_1000=15, DICT_ARUCO_ORIGINAL = 16}"
"{id | | Marker id in the dictionary }"
"{ms | 200 | Marker size in pixels }"
"{bb | 1 | Number of bits in marker borders }"
"{si | false | show generated image }";
}
int main(int argc, char* argv[]) {
CommandLineParser parser(argc, argv, keys);
parser.about(about);
if (argc < 4) {
parser.printMessage();
return 0;
}
int dictionaryId = parser.get<int>("d");
int markerId = parser.get<int>("id");
int borderBits = parser.get<int>("bb");
int markerSize = parser.get<int>("ms");
bool showImage = parser.get<bool>("si");
String out = parser.get<String>(0);
if (!parser.check()) {
parser.printErrors();
return 0;
}
Ptr<aruco::Dictionary> dictionary =
aruco::getPredefinedDictionary(aruco::PREDEFINED_DICTIONARY_NAME(dictionaryId));
Mat markerImg;
aruco::drawMarker(dictionary, markerId, markerSize, markerImg, borderBits);
if (showImage) {
imshow("marker", markerImg);
waitKey(0);
}
imwrite(out, markerImg);
return 0;
}
the error:
> Build started... 1>------ Build started: Project: TESTOPENCV,
> Configuration: Release x64 ------ 1>main.cpp error C2039:
> 'PREDEFINED_DICTIONARY_NAME': is not a member of 'cv::aruco'
> 1>C:\OpenCVLIB\install\include\opencv2\aruco.hpp(11): message : see
> declaration of 'cv::aruco' error C3861: 'PREDEFINED_DICTIONARY_NAME':
> identifier not found
> 1>C:\Users\ilyas\source\repos\TESTOPENCV\main.cpp(47,12): error C2039:
> 'drawMarker': is not a member of 'cv::aruco'
> 1>C:\OpenCVLIB\install\include\opencv2\aruco.hpp(11): message : see
> declaration of 'cv::aruco' 1 error C3861: 'drawMarker': identifier not
> found 1>Done building project "TESTOPENCV.vcxproj" -- FAILED.
> ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I am new to Arcuo marker, so I have no idea what do and what to change and to what. Any help would be really appreciated!
I tried looking it up, but could not find any answer on the internet. It says that Arcuo marker library has been changed but I am not sure what changed to what.

I build opencv 3.4 with Gstreamer MSVC 1.16.1, and now imread and VideoCapture not working

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)

errors when i use bgslibrary example code

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

OpenCV: Can't find modules from contrib repository (Tracker, selectROI)

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!

OpenCV 3.2.0, Visual Studio 2015, Windows 7

I installed the pre-built libraries OpenCV 3.2.0 on Windows 7 following the instructions here and I am encountering errors when trying to use them in Visual Studio 2015.
The variable OPENCV_DIR is set correctly:
C:\>echo %OPENCV_DIR%
C:\OpenCV\Build\x64\vc14
C:\>dir %OPENCV_DIR%
Le volume dans le lecteur C s'appelle OS
Le numéro de série du volume est 1234-ABCD
Répertoire de C:\OpenCV\Build\x64\vc14
27/01/2017 17:10 <REP> .
27/01/2017 17:10 <REP> ..
27/01/2017 17:11 <REP> bin
27/01/2017 17:10 <REP> lib
0 fichier(s) 0 octets
4 Rép(s) 19 236 450 304 octets libres
C:\>
And the rules for the project are like there
With the libraries specified as
opencv_calib3d320d.lib
opencv_core320d.lib
opencv_features2d320d.lib
opencv_flann320d.lib
opencv_highgui320d.lib
opencv_imgcodecs320d.lib
opencv_imgproc320d.lib
opencv_ml320d.lib
opencv_objdetect320d.lib
opencv_photo320d.lib
opencv_shape320d.lib
opencv_stitching320d.lib
opencv_superres320d.lib
opencv_ts320d.lib
opencv_video320d.lib
opencv_videoio320d.lib
opencv_videostab320d.lib
But when I try to compile the basic test project written there
#include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#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;
}
I get the error
1>------ Build started: Project: ImageCorrection, Configuration: Debug x64 ------
1> test.cpp
1>LINK : fatal error LNK1104: cannot open file 'opencv_calib3d320d.lib'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I am really new to compilation and linking on Windows and Visual Studio (I am used to g++ on Linux) so I really have no idea of what I am doing wrong here.
I think that it might have something to do with the dynamic linking, but I do not know neither how to investigate nor how to solve it.
Ant help is most appreciated! :D
OpenCV 3.2 prebuild binaries have just the world lib:
opencv_world320.lib for release
opencv_world320d.lib for debug
That's all you need to link.