Using mingw with opencv -- init error - opencv

I use Eclipse CDT for developing C with mingw. I also add opencv libary. Everything compiled without problems. But if I start the compiled application (using a opencv-function) there is an init error. If I only include the .h-files without using a function it works.
The code:
#include <opencv2/opencv.hpp>
using namespace std;
int main() {
cout << "!!!Streaming!!!" << endl; // prints !!!Streaming!!!
// Nothing but create a window
cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE);
cvMoveWindow("mainWin", 100, 100);
cvWaitKey(0);
return 0;
}
Error-Image: http://i.stack.imgur.com/zdmT7.png
If I do not use a cv.. - function there will be no init error. Even if I include opencv2/opencv.hpp
I do not have an idea how it works.
Hope you can help.

I found the solution. The opencv-dll-files for mingw are damaged. I rename the visualstudio dlls to the names of the mingw-dlls and put it directly to in the exe folder and it works.

Related

Why does my code crash when libvlc_media_new_path() is called?

after several days of trying myself to solve my problem I would like to kindly ask for your help:
I am trying to make the libvlc / SDL 2.0 tutorial working.
I am coding in Visual Studio 2022 in x86 C++ Console.
I have linked the libvlc library path and include path and have added the libvlc.lib file in my project linker settings.
The program compiles without error and crashes when libvlc_media_new_path is called.
You see all different formats of path I have used in my minimal reproducible example below:
My sources:
I downloaded the vlc master from Github to get the headers / include directory.
I downloaded the vlc-3.0.17.4-win32 release and from there took the libvlc.dll.
From the libvlc.dll I created the lib file following a visual studio command prompt procedure.
What i noticed is that the function libvlc_media_new_path() only takes the path as an argument now. All examples i find in the internet are with the libvlc instance AND the path as arguments.
Thank you so much for your help!
#include <stdlib.h>
#include "vlc/vlc.h"
int main(int argc, char* argv[]) {
libvlc_instance_t* libvlc;
libvlc_media_t* m;
libvlc_media_player_t* mp;
libvlc = libvlc_new(0, NULL);
if (NULL == libvlc) {
printf("LibVLC initialization failure.\n");
return EXIT_FAILURE;
}
m = libvlc_media_new_path("/1.mp4");
//m = libvlc_media_new_path("C:\\Programmieren\\PACA\\1.mp4");
//m = libvlc_media_new_path("C:/Programmieren/PACA/1.mp4");
//m = libvlc_media_new_path("C://Programmieren//PACA//1.mp4");
//m = libvlc_media_new_path("C:\Programmieren\PACA\1.mp4");
//m = libvlc_media_new_path("file:///C:/Programmieren/PACA/1.mp4");
mp = libvlc_media_player_new_from_media(libvlc, m);
return 0;
}
If you go to Github and click on the Tags link, you can get the headers for version 3.0.17.4. In there you will see that libvlc_media_new_path takes an instance as an argument.
The other option would be to get or build the 3.0.18 DLL.

How to use opencv cuda module log function

I'm trying to work with Opencv CUDA module, specially refer to cv::cuda::log function.
First, I'll give to details Opencv compilation.
I compiled Opencv with WITH_CUDA flag on, took the libs and dlls from the compilation, however I copied the headers files from the downloaded opencv folder, since the compilation folder does't include headers by default.
I wonder, whether is this the right thing to do ?
Second, I tried to use the cv::cuda:: function.
I include the cuda.hpp header
#include "opencv2/core/cuda.hpp"
cv::cuda::GpuMat source, dest;
GpuMat compiles great for me, However I don't know which file should I include in order to work with the log function. when I write the following line
cv::cuda::log(source, dest);
I kept on getting the error message:
error: C2039: log in not a member of cv::cuda
Windows 7, Visual studio 2013, Opencv 3.0.0, platform: 64 bit, CUDA toolkit 6.5
Third, I'd like to know about Opencv CUDA implementation, does it utilize npp functionality? Opencv vs npp, which one is better to use ?
I could easly write my code using npp, however I'd like to know the opencv CUDA module.
Thanks
After couple days of searching, I'd like to share my knowledge
First thing I was doing wrong, was taking the headers from Opencv compilation, the right thing to do is taking the header from all the Opencv modules (each module individually).
Second, After Opencv compilation with CUDA flag everything worked great.
Third, Several opencv CUDA functions does utilize NPP
Forth, Use github
This code should work for OpenCV 3.1:
#include <opencv2/opencv.hpp>
#include <opencv2/cudaarithm.hpp>
int main()
{
cv::Mat img = cv::imread("img.jpg", cv::IMREAD_GRAYSCALE);
cv::Mat img_32f;
img.convertTo(img_32f, CV_32F);
//To avoid log(0) that is undefined
img_32f += 1.0f;
cv::cuda::GpuMat gpuImg, gpuImgLog;
gpuImg.upload(img_32f);
cv::cuda::log(gpuImg, gpuImgLog);
cv::Mat imgLog, imgLog_32f;
gpuImgLog.download(imgLog_32f);
double min, max;
cv::minMaxLoc(imgLog_32f, &min, &max);
imgLog_32f.convertTo(imgLog, CV_8U, 255.0/(max-min), -255.0*min/(max-min));
cv::imshow("img", img);
cv::imshow("imgLog", imgLog);
cv::waitKey(0);
return 0;
}

fatal error LNK1104: cannot open file 'opencv_calib3d246.dll'

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.

VideoCapture OpenCV 2.4.2 error in windows

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.

C++ Eclipse OpenCV : .exe file and binaries generated, but no image displayed

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.

Resources