Im using eclipse with opencv and i have this simple project:
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, char** argv)
{
Mat im = imread(argc == 2 ? argv[1] : "lena.jpg", 1);
if (im.empty())
{
cout << "Cannot open image!" << endl;
return -1;
}
imshow("image", im);
waitKey(0);
return 0;
}
It apears to be correct acording to eclipse and it compiles just fine. But if i try to run it on debug mode from eclipse nothing happend and if i try to execute the .exe i get this error:
EDIT: These images are in spanish, but the error is exactly the same that the one in this post: opencv 2.4 error in windows 7 64 bit
I am runing it on a virtual machine with windows 7 x86.
PS: Sry for my english!
There's a chance that when Eclipse runs your application it looks for lena.jpg in a directory where this file is not present.
Make sure you put the JPG in the same folder as your source files and also in the same folder as the .exe.
Your code seems legit, and this problem shouldn't be happening. The best way to figure out what's really going on is to use the debugger and find out which of the calls trigger the error.
Related
I have the following program, which is the same as this tutorial page for OpenCV 3.4.0. I am using Visual Studio 2017 Community on a 64-bit laptop with Windows 10 Enterprise 64-bit.
#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;
}
With the includes and linker directories and libraries set up for this project, the solution builds just fine. But when I run the program, I get the following error:
"The code execution cannot proceed because zlibd1.dll was not found. Reinstalling the program may fix this problem."
From my initial research, it's not necessarily coming from Visual Studio 2017. When I try to create a new project, I do not have the option to select "Win32 Console Application." The project this source code sits in is of type Windows Console Application under Visual C++, supporting .NET Framework 4.5.
What am I missing here?
Based on the tutorial, I should be using only the libraries and the dynamic link libraries OpenCV 3.4.0 provides. I remember at one point using NuGET to try to install OpenCV 3.4.0 again, as explained here, when I was trying to solve the compiler error regarding fopen from a file within OpenCV 3.4.0 itself.
Okay, apparently it was a problem regarding my system path. It was not set right, Before, what I had was the path variable set to the following:
%OPENCV_DIR%\lib
%OPENCV_DIR%\bin
with $(OPENCV_DIR) being just the build directory of OpenCV 3.4.0.
But the directories there do not exist, and hence the libraries couldn't be found. So, I replaced them with this:
%OPENCV_DIR%\x64\vc15\bin
%OPENCV_DIR%\x64\vc15\lib
and the program now runs. What was I thinking back there?
Either way, important lesson to note: When you are getting a popup message saying the program cannot be opened because a library is missing, and is part of OpenCV 3.4.0, be sure that your system path in the Windows 10 System Advanced Settings is an OpenCV directory that exists.
This package has a problem to run under debug and result in zlibd1.dll problem. Switch to release if you can or use different nuget package.
I am using Visual Studio 2010 with OpenCV 2.3.1 Libraries. I just wanted to stream video from an IP camera and make some processing in it. While trying so, it worked properly when I ran the project in VS2010. But it is not working when I tried running it as an EXE file. But the same program is working for Non-IP cameras like USB Web cams (Both as project file and as an .EXE file)
I dropped the DLL files which are all needed to the folder where my .EXE file is located (The DLL files are opencv_calib3d231d.dll,opencv_core231d.dll, opencv_features2d231d.dll, opencv_flann231d.dll, opencv_highgui231d.dll, opencv_imgproc231d.dll, opencv_objdetect231d.dll, opencv_video231d.dll, tbb_debug.dll)
I am having an error saying "Bad Flag (parameter or structure field) (Unrecognized or unsupported array type) in unknown function, file C:\slave\WinInstallerMegaPack\src\opencv\modules\core\src\array.cpp, line 2482"
My code is
#include "stdafx.h"
#include<iostream>
#include"opencv2\opencv.hpp"
#include"opencv2\highgui\highgui.hpp"
#include"opencv\cv.h"
using namespace std;
using namespace cv;
int _tmain(int argc, _TCHAR* argv[])
{
Mat f;
const string s="http://<username:password>#<IP address:portno>/axis- cgi/mjpg/video.cgi?.mjpg";
VideoCapture cap;
cap.open(s);
if(!cap.isOpened())
cout<<"Cannot be accessed";
while(8)
{
cap>>f;
imshow("Live stream",f);
if(waitKey(30)==27)
break;
}
return 0;
}
Somebody Please help me get rid of this...
Thanks in Advance...
Thank you. Thank you. And thanks a lot #Micka. I got my problem solved by just linking the opencv_ffmpeg.dll to my program. Or dropping the dll file in to the folder where the .EXE file exists. Thank you once again.
I installed OpenCV version 2.4.3 using Visual Sudio 10 as the IDE (on windows 7 64-bit).
The problem is that once I installed it and am running even a simple application like that of loading an image it is giving me an error
The program '[8120] pms1.exe: Native' has exited with code -1073741811 (0xc000000d)
I am getting the same error for any code that I am trying to run. I am not getting any build errors. Build is getting succeeded but when I run it it throws me this.
Note: a sample code which gave me the error
#include <opencv\cv.h>
#include <opencv\highgui.h>
using namespace cv;
int main()
{
Mat image;
VideoCapture cap;
cap.open(0);
namedWindow(“window”, 1);
while(1) {
cap>>image;
imshow(“window”, image);
waitKey(33);
}
return 0;
}
Make sure that your executable and the opencv dll files it calls are both 32-bit or 64-bit.
Most probably the capture interface failed to open device 0, so cap>>image; is probably causing the error. You just don't know it because you forgot to check the success of open():
VideoCapture cap;
cap.open(0);
if (!cap.isOpened())
{
// print error message and
// quit the application
}
Experiment to pass other values for open(), like -1 or 2.
I'm new here and I've been trying to set up OpenCV on my codeblocks IDE. I'm not sure whats wrong. I'm using windows 7, 64bit system, and codeblocks, I also downloaded 2-4.3 version of OpenCV.
I tried following the manual intsructions here, but that was of no help: http://opencv.willowgarage.com/wiki/CodeBlocks
Even though I'm trying to use codeblocks I also tried:
Installing OpenCV 2.4.3 in Visual C++ 2010 Express
I have my path set to:
C:\OpenCV\build\x64\vc10\bin
And for the compiler settings under tab "search directories":
"Compiler" : C:\OpenCV\build\include
"Linker" : C:\OpenCV\build\x64\vc10\lib
And then under the tab "Linker settings" I have all the .lib files from
C:\OpenCV\build\x64\vc10\lib
I tried running this as my test program and it gives me an error readout connecting to
operations.hpp header file:
#include "opencv2/highgui/highgui.hpp"
#include "iostream"
using namespace cv;
using namespace std;
int main()
{
Mat im = imread("c:/full/path/to/lena.jpg");
if (im.empty())
{
cout << "Cannot load image!" << endl;
return -1;
}
imshow("Image", im);
waitKey(0);
}
The error says:
C:\OpenCV\build\include\opencv2\core\operations.hpp|3915|error: expected primary-expression before '>' token|
C:\OpenCV\build\include\opencv2\core\operations.hpp|3915|error: expected primary-expression before ')' token|
....and a bunch of other stuff, but those are the first 2 errors.
So my 2 fold question is this:
1) Did I set up my IDE correctly?
2) Is there something wrong with the OpenCV code?
The solution of this problem is to edit the line 3915 of operations.cpp file. The correct return argument is
return _create(name).Ptr<_Tp>();
have you tried include opencv core?
#include "opencv2/core/core.hpp"
my assumption is you don't use the core function, so your code not recognize some function.
I'm a starter in OpenCV. My programming environment is VC++ Express 2010 + OpenCV 2.4.2 + Win 7 64 bit.
I use purely 32bit configuration in my VC++ and Path.
I type in the following code:
#include "opencv2\highgui\highgui.hpp"
#include "opencv2\core\core.hpp"
using namespace cv;
int main(int argc, char** argv) {
char* imgPath = "logo.png";
Mat img = imread(imgPath);
namedWindow( "Example1", WINDOW_AUTOSIZE);
imshow("Example1", img);
waitKey(0);
return 0;
}
Then I compile and run. It does come up with a window (but without picture) but then gave me this (a runtime error?)
Unhandled exception at 0x770515de in Helloworld2.exe: Microsoft C++ exception: cv::Exception at memory location 0x001ef038..
Then I change the imread into cvLoadImage and it works without any errors.
Can someone tell me what's wrong?
I have tried the code you have given. It works perfectly fine with my installation of OpenCV.
However I am getting a warning at the line:
char* imgPath = "logo.png";
main.cpp:6:21: warning: deprecated conversion from string constant to 'char*' [-
Wwrite-strings]
Which i think is nothing serious to make the code crash, however it might be the problem in your case, as I am not using VC++ to compile.
What you can try to check if this is the issue is to replace imgPath with directly the string, so the code will now be like
Mat img = imread("logo.png");
I also got this issue, but I fixed it with the following. The point is using absolute path other than relative path, and change "\" with "/" in the file path.
#include <opencv2\core\core.hpp>
#include <opencv2\highgui\highgui.hpp>
int main() {
cv::Mat image = cv::imread("D:/projects/test/Debug/1.jpg");
if (image.empty()) {
return 0;
}
cv::namedWindow("my image");
cv::imshow("my image", image);
cv::waitKey(5000);
return 1;
}
The difference between cvLoadImage and imread can be seen on opencv documentation:
C++: Mat imread(const string& filename, int flags=1 )
and
C: CvMat* cvLoadImageM(const char* filename, int
iscolor=CV_LOAD_IMAGE_COLOR )
But there is an implicit conversion from const char * to string. As masad noted, this conversion is deprecated, so it is very compiler dependent.
As cvLoadImage works for you, it seems that you should change your code to something like this:
#include "opencv2\highgui\highgui.hpp"
#include "opencv2\core\core.hpp"
#include <string>
using namespace cv;
int main(int argc, char** argv) {
std::string imgPath("logo.png");
Mat img = imread(imgPath);
namedWindow( "Example1", WINDOW_AUTOSIZE);
imshow("Example1", img);
waitKey(0);
return 0;
}
There has been some problems with C++ interface in Visual Studio, but you may try to see if it works for you.
I had the same problem and I came across Installing OpenCV 2.4.3 in Visual C++ 2010 Express and it mentions to use the updated set of libraries *d.lib when adding dependencies for the Linker. I tried it and the C++ interface worked. Not sure if this is the case in general. I am using OpenCV 2.4 and Visual Studio 2010 on a 64 bit Windows machine.
I got the similar problem with you. When I use the imread function, the program crash with system error message:
opencv_debug.exe 中的 0x0036299f 处未处理的异常: 0xC0000005: 读取位置 0xcccccccc 时发生访问冲突
Then I change the imread into cvLoadImage and it works without any errors.
Finally, I fix the problem, it comes because I used VS2008 project with VS2010 compiled dll.
Here is my story.
Environment: VS2008 + opencv2.4.7
First, I just follow the link http://docs.opencv.org/doc/tutorials/introduction/windows_visual_studio_Opencv/windows_visual_studio_Opencv.html, and compile the my test project.
But, When I run my test project, the system error dialog tells me that I lost MSVCP100D.dll MSVCR100D.dll. So I download the two dll, the dll lost problem is solved, but the problem is crash on run time.
Notice that ahead link, it says:
it means that, in opencv2.4.7, they only provide dlls which compiled in vs2010 or vs2012, not vs2008.
When I compiling vs2008 project with dlls which compiled by vs2010, I get the wired problem.
How can I fix this problem?
use the older opencv version such as opencv2.3, this version contains the vs2008 compiled dll.
compile the opencv by yourself.
I have noticed that your environment is: VC++ Express 2010 + OpenCV 2.4.2 + Win 7 64 bit.
Be sure OPENCV_DIR is set right.
setx -m OPENCV_DIR D:\OpenCV\Build\x64\vc10