I have installed Codeblocks with MingW, followed the instructions given HERE
I downloaded CodeBlocks with MingW. Followed the instructions in the above link, and wrote the following program
Code:
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace std;
using namespace cv;
int main()
{
cout<<"Testing";
Mat image;// new blank image
image = cv::imread("test.png", 0);// read the file
namedWindow( "Display window", CV_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;
}
Default compiler options set to GCC Compiler.
When I clicked Build and Run button on the IDE, it showed an "Entry Point Not Found" error message that says "The Procedure entry point__gxx_personality_v0 could not be located in the dynamic link library libstdc++-6.dll"
I dont understand what is happening. I have been trying to run this small code with various IDEs. I could not understand what went wrong.
I am the creator of the tutorial you followed! I've updated it to fix this issue - Namely the best way to use OpenCV with MinGW on Windows currently is to build your own binaries using cmake.
Best,
Kevin
Related
I am trying to run YOLOv3 on Visual Studio 2019 using CUDA 10.2 with cuDNN v7.6.5 on Windows 10 using NVidia GeForce 930M. Here is part of the code I used.
#include <fstream>
#include <sstream>
#include <iostream>
#include <opencv2/dnn.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
using namespace cv;
using namespace dnn;
using namespace std;
int main()
{
// Load names of classes
string classesFile = "coco.names";
ifstream ifs(classesFile.c_str());
string line;
while (getline(ifs, line)) classes.push_back(line);
// Give the configuration and weight files for the model
String modelConfiguration = "yolovs.cfg";
String modelWeights = "yolov3.weights";
// Load the network
Net net = readNetFromDarknet(modelConfiguration, modelWeights);
net.setPreferableBackend(DNN_BACKEND_CUDA);
net.setPreferableTarget(DNN_TARGET_CUDA);
// Open the video file
inputFile = "vid.mp4";
cap.open(inputFile);
// Get frame from the video
cap >> frame;
// Create a 4D blob from a frame
blobFromImage(frame, blob, 1 / 255.0, Size(inpWidth, inpHeight), Scalar(0, 0, 0), true, false);
// Sets the input to the network
net.setInput(blob);
// Runs the forward pass to get output of the output layers
vector<Mat> outs;
net.forward(outs, getOutputsNames(net));
}
Although I add $(CUDNN)\include;$(cudnn)\include; to Additional Include Directories in both C/C++ and Linker, added CUDNN_HALF;CUDNN; to C/C++>Preprocessor Definitions, and added cudnn.lib; to Linker>Input, I still get this warning:
DNN module was not built with CUDA backend; switching to CPU
and it runs on CPU instead of GPU, can anyone help me with this problem?
I solved it by using CMake, but I had first to add this opencv_contrib then rebuilding it using Visual Studio. Make sure that these WITH_CUDA, WITH_CUBLAS, WITH_CUDNN, OPENCV_DNN_CUDA, BUILD_opencv_world are checked in CMake.
I had a similar issue happen to me about a week ago, but I was using Python and Tensorflow. Although the languages were different compared to C++, I did get the same error. To fix this, I uninstalled CUDA 10.2 and downgraded to CUDA 10.1. From what I have found, there might be a dependency issue with CUDA, or in your case, OpenCV hasn't created support yet for the latest version of CUDA.
EDIT
After some further research it seems to be an issue with Opencv rather than CUDA. Referencing this github thread, if you installed Opencv with cmake, remove the arch bin version below 7 on the config file, then rebuild/reinstall Opencv. However, if that doesn't work, another option would be to remove CUDA arch bin version < 5.3 and rebuild.
I have this simple code to open an image but it shows blank image in the "Video" window. I have checked release and debug lib's to make sure. It is in release mode and the lib is release lib. The picture is there, and I also tried full path for the image but still doesn't work. Also tried different image formats: jpg, png, bmp. It is OpenCV 3.4.1 release, and VS 2017 (also tried 2015).
#include "stdafx.h"
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main()
{
namedWindow("Video");
Mat frame1 = imread("Penguins.bmp", CV_LOAD_IMAGE_COLOR );
imshow("Video", frame1);
system("Pause");
return 0;
}
Thanks in advance
You need to use the waitKey() function after imshow(). You can pass in a delay parameter to show the image for a certain time (in milliseconds).
Example:
#--- It will display the image for 30 ms
waitKey(30);
#--- It will display the image until a key is pressed
waitKey();
Check THIS PAGE for more.
There is also a demo example shown HERE
I'm trying to run visual c++ with OpenCV. I have linked the OpenCV to Visual studio 2012. when I tried to run the code, it's giving me an error;
LINK : fatal error LNK1104: cannot open file 'opencv_calib2d246.dll'
Here's what I was trying to do:
#include "stdafx.h"
#include "opencv2\highgui\highgui.hpp"
#include "opencv2\core\core.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],CV_LOAD_IMAGE_UNCHANGED);
if(! image.data)
{
cout<<"couldn't open or find the image"<<endl;
return -1;
}
namedWindow("Display Window",WINDOW_AUTOSIZE);
imshow("Display Window",image);
waitKey(0);
return 0;
}
I have included all the libraries. I'm using OpenCV 2.4.6, on windows 7 32 bit system.
Anything more I have to add, or do I have to initialize it in the program?
Update
The path for OpenCV in my hard disk :E:\opencv\opencv. Path in the system environment variable: %OPENCV_DIR%\x86\vc11\bin;, where I have created a new variable as OPENCV_DIR and have given the path as E:\opencv\opencv\build. And in linker\command line
/OUT:"E:\VS2012 Projects\cvtest\Debug\cvtest.exe" /MANIFEST /NXCOMPAT /PDB:"E:\VS2012 Projects\cvtest\Debug\cvtest.pdb" /DYNAMICBASE "opencv_calib3d248.lib" "opencv_calib3d248d.lib" "opencv_contrib248.lib" "opencv_contrib248d.lib" "opencv_core248.lib" "opencv_core248d.lib" "opencv_features2d248.lib" "opencv_features2d248d.lib" "opencv_flann248.lib" "opencv_flann248d.lib" "opencv_gpu248.lib" "opencv_gpu248d.lib" "opencv_highgui248.lib" "opencv_highgui248d.lib" "opencv_imgproc248.lib" "opencv_imgproc248d.lib" "opencv_legacy248.lib" "opencv_legacy248d.lib" "opencv_ml248.lib" "opencv_ml248d.lib" "opencv_nonfree248.lib" "opencv_nonfree248d.lib" "opencv_objdetect248.lib" "opencv_objdetect248d.lib" "opencv_ocl248.lib" "opencv_ocl248d.lib" "opencv_photo248.lib" "opencv_photo248d.lib" "opencv_stitching248.lib" "opencv_stitching248d.lib" "opencv_superres248.lib" "opencv_superres248d.lib" "opencv_ts248.lib" "opencv_ts248d.lib" "opencv_video248.lib" "opencv_video248d.lib" "opencv_videostab248.lib" "opencv_videostab248d.lib" "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" /DEBUG /MACHINE:X86 /INCREMENTAL /PGD:"E:\VS2012 Projects\cvtest\Debug\cvtest.pgd" /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:"Debug\cvtest.exe.intermediate.manifest" /ERRORREPORT:PROMPT /NOLOGO /TLBID:1
Now I'm not able to load image. No fatal errors and nothing. It is considering the if statement and not loading anything.
Any suggestions?
You need to set up more than just your linker dependencies and it is very likely you have missed a step.
I would suggest following this tutorial as it will get you setup completely.
I have a problem using VideoCapture class with OpenCV 2.4.2 under windows XP 32bits.
It doesn't open any file or camera and fixing it's being a pain.
Im using visual studio 2010 but i have also tried the code in QTcreator with the same result.
The testing code is the following:
#include "opencv/cv.h"
#include "opencv/highgui.h"
#include <iostream>
#include <string>
#include <iomanip>
#include <sstream>
using namespace cv;
using namespace std;
int main()
{
const char* videoPath = "C:/video/";
string videoName = string(videoPath) + "avi.avi";
VideoCapture cap(videoName);
if(!cap.isOpened())
{
std::cout<<"Fail"<<std::endl;
return -3;
}
return 0;
}
The output is always '-3'.
Qt Creator shows a
warning: Error opening file (../../modules/highgui/src/cap_ffmpeg_impl.hpp:361)
I debugged it and the problem appears in the first line of:
CvCapture* cvCreateFileCapture_FFMPEG_proxy(const char * filename)
{
CvCapture_FFMPEG_proxy* result = new CvCapture_FFMPEG_proxy;
if( result->open( filename ))
return result;
delete result;
#if defined WIN32 || defined _WIN32
return cvCreateFileCapture_VFW(filename);
#else
return 0;
#endif
}
in the cap_ffmpeg.cpp internal file.
I have tested the same code in a mac under snow leopard and it works. No surprises here since it must be a library issue.
I have opened the avi file with the same path route using the c-function cvCapture easy and fast.
I got all the dlls of 'C:\opencv\opencv\build\x86\vc10\bin'
included in mi debug file. I got the tbb.dll and all the 'C:\opencv\opencv\3rdparty\ffmpeg' content included too.
This is drving me crazy so any help would be appreciated.
Thanks in advance.
In my case, the same problem was resolved after deleting all opencv_***.dll files in C:\Windows\System32. So, I use the dll files just through the path like "%PATH%;C: \Program Files \OpenCV2.4.2\build\x86\vc10/bin". Please try it.
I also faced with this problem and solved it by correct the path of the function:
VideoCapture cap(videoName);
If the AVI file of videoName does't exist, it will be an error:
(../../modules/highgui/src/cap_ffmpeg_impl.hpp:XXX)
where XXX represents the line number.
I had the same issue with the open method whilst running under Windows 8 (64bit), opencv 2.4.10. IDE is running in x86.
I found that running the application in release configuration solved the problem.
Stumbled across the answer because I had the same issue with imread. Issue is presented in the this thread.
imread not working in Opencv
See the fix I found below, for mp4 files.
I faced the same issue on Windows 7, using OpenCV 2.4.9. I am using the java wrapper for opencv.
Matthias Krings has done a lot of research for this. See this. Apparently this is an issue based on the video file type. With .avi files, it seems to work for a lot of people. Unfortunately his solution of setting OPENCV_DIR did not work for me. But his comments in the bug listing gave me a hint to fix the issue.
You have to do two things:
Set java.library.path to include the directory {opencv\install\dir}opencv-2.4.9\build\x86\vc10\bin. You can set the variable using the -D option on the java command line: java -Djava.library.path=PATH_TO_YOUR_DLL .... Also fetch this variable from your environment, using System.getProperty(...), and print it before calling loadLibrary(), to verify that the path setting is working.
And in your java class, load the ffmpeg dll using System.loadLibrary("opencv_ffmpeg249");. The loadLibrary() function should be invoked from within a static block in java.
There is a file named opencv_ffmpeg249.dll in the java.library.path that we set.
This works on ubuntu also, for .so files.
I too faced the same issue and resolved after pointing to the correct location of the input video.
Here's my code (the first DisplayImage.cpp code in the OpenCV documentation)
/*
* DisplayImage.cpp
*
* Created on: Dec 25, 2011
* Author: Arcturus */
#include <iostream>
#include <opencv2\opencv.hpp>
using namespace cv;
using namespace std;
int main(int argc, char** argv){
Mat image;
image = imread(argv[1], 1);
if(argc!=2 || !image.data){
cout<<"no image data";
return -1;
}
namedWindow("Display Image", CV_WINDOW_AUTOSIZE);
imshow("Display Image", image);
waitKey(10000);
return 0;
}
Build complete, executable generated, binaries generated.
I have my image - blackbuck.bmp- in the DisplayImage Debug folder. To run the code, I go to Run> Run Configurations. Select the DisplayImage Debug exe file, key in blackbuck.bmp (also tried it with absolute path) and run it.
On the top of the console, I get the message : DisplayImage Debug. And it displays no image at all. What could be wrong here?
I am running it on Eclipse, using CDT.
Thank you for your time!
EDIT: Problem solved!!! I had to copy all the dll files from the library folder to the folder in which my executable file was being generated. I still do not understand why, though. After all, the linker was already linking the library folder containing all the dlls. If someone could explain this, it would be of great help for future debugging. Thank you karl and mevotron for your time :)
EDIT 2: From the msdn website:
"A potential disadvantage to using DLLs is that the application is not self-contained; it depends on the existence of a separate DLL module. The system terminates processes using load-time dynamic linking if they require a DLL that is not found at process startup and gives an error message to the user. The system does not terminate a process using run-time dynamic linking in this situation, but functions exported by the missing DLL are not available to the program."
I think this answers my question. Perhaps this means eclipse uses load-time dynamic linking.
How did you compile OpenCV with MinGW (i.e., what were your BUILD_TYPE and SSE* options set to during the CMake configuration)? The reason I ask, is that there is a known bug with SSE optimizations that will cause highgui operations to crash when using MinGW built versions. See my other SO answer here.