I am working with OpenCV version 3.2.0 in Visual Studio 2015 and have been able to access my webcam until all of a sudden when I was working on it this morning. I can't figure out where this problem is coming from. I now get:
It doesn't throw any errors but it also doesn't show any input through the webcam
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
using namespace std;
using namespace cv;
int main(int argc, char** argv)
{
VideoCapture cap;
cap.open(0);
if (!cap.isOpened())
{
printf("--(!)Error opening video capture\n");
return -3;
}
Mat image;
namedWindow("Image", CV_WINDOW_AUTOSIZE);
while (1)
{
cap.read(image);
imshow("Image", image);
waitKey(30);
}
return 0;
}
Has anyone encountered this error before?
Edit:
Things I have looked at:
My webcams that I have work in things like Google Hangouts so I don't think it's a webcam issue.
Also, I uninstalled Visual Studio 2015 and installed Visual Studio 2017 to see if reinstalling would work and still get the same results.
Edit:
I am getting the error <information not available, no symboles loaded for opencv_world320d.dll> when I create a new VideoCapture object. I am pretty sure I have everything included correctly.
Configuration Properties -> C/C++ -> Additional Include Directories:
$(OPENCV_BUILD)\include
Configuration Properties -> Linker -> General:
$(OPENCV_BUILD)\x64\vc14\lib
Configuration Properties -> Linker -> Input:
opencv_world320d.lib
I encountered the same problem after obtaining Opencv via compiling and building source using CMake. Then, I deleted them and installed Opencv from prebuilt binaries. I have run the code again and there was no problem.
As suggested by #michael scolfield, it was a problem with my antivirus blocking my webcam. I couldn't figure out how to exclude my Visual Studio directory so I just tried uninstalling it and it worked. It would be nice to have antivirus and have this working so I'll need to figure that out. But for temps this will work.
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.
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.
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
I am having so much trouble installing openCV 2.3 with visual studio 2010. Crash after crash, installation after installation and after several weeks I've had no luck.
Unfortunately there are no installation documents for openCV 2.3 and the directory structure and file locations are different from openCV 2.2 which makes the current tutorials almost useless. :(
Has anyone out there had any success with openCV 2.3? Can someone please try it and let me know if its an openCV build issue or my setup?
Or maybe someone can suggest an alternative to openCV. What my end goal is, is to get Pixel info, use inpaint functions, and basic image processing for After Effects and Maya.
EDIT: Sorry I thought I posed the error! This is what happens when I run the code:
#include <iostream>
#include <cv.h>
#include <highgui.h>
using namespace cv;
int main()
{
Mat image;
image = imread( "c:/image1.png", 1 );
namedWindow( "Gray image", CV_WINDOW_AUTOSIZE );
imshow( "Gray image", image );
waitKey(0);
return 0;
}
It runs until imshow. If I comment out imshow it runs fine with no errors.
Here is the errors when I add IMSHOW:
Unhandled exception at 0x76bfb727 in openCV_test.exe: Microsoft C++ exception: cv::Exception at memory location 0x0015ec20. and it gives me the option to break or continue.
This is what the output window shows:
First-chance exception at 0x76bfb727 in openCV_test.exe: Microsoft C++ exception: cv::Exception at memory location 0x0015ec20..
Unhandled exception at 0x76bfb727 in openCV_test.exe: Microsoft C++ exception: cv::Exception at memory location 0x0015ec20..
It then goes on to open SYSTEM.CPP and give me this:
- exc {msg="......\modules\core\src\array.cpp:2482: error: (-206) Unrecognized or unsupported array type
" code=-206 err="Unrecognized or unsupported array type" ...} const cv::Exception &
+ std::exception {_Mywhat=0x00000000 _Mydofree=false } std::exception
+ msg "......\modules\core\src\array.cpp:2482: error: (-206) Unrecognized or unsupported array type
" std::basic_string,std::allocator >
code -206 int
+ err "Unrecognized or unsupported array type" std::basic_string,std::allocator >
+ func "" std::basic_string,std::allocator >
+ file "......\modules\core\src\array.cpp" std::basic_string,std::allocator >
line 2482 int
Thanks!
I have OpenCV2.3 and had no problem to install it with Visual Studio v9.0.
What you should do to compile and run correctly your project in all the Visual Studio versions :
Properties of your project (right click on it)
C/C++
General
Include directory add the < your directory >\OpenCV2.3\include\opencv2, < your directory >\OpenCV2.3\include\opencv and < your directory >\OpenCV2.3\include
Linker
General
Add lib directory < your directory >\OpenCV2.3\lib
Input
Add all the libs like opencv_core230d.lib opencv_highgui230d.lib and so on...
Then don't forget to add the dll to your system path.
Configuration panel > System > Advanced > Environment variables > Path
you can add a user environment path which will override the other one,
just click New (if you have never added directory to your system path before) and write the path eg : < your directory >\OpenCV2.3\bin
Without more information, I hope it could help...
Julien,
Sometimes, the compiler cannot find the dll even if you have the correct path settings. At that point try copying the dll files from the openCV folder to ur current project (not solution) folder.
Rather than copy pasting I'll just link: http://theroundedengineer.blogspot.com/2011/07/opencv-23-for-vs-2008-from-source.html
Hopefully that helps. Granted I'm far from an expert on the differences between VS 2008 and VS 2010.
I got exactly the same problem. I couldn't read any image. I checked the data flag and image size. The flag indicated error and the size was always (0, 0). Although I do not know the actual cause, I somehow could avoid the problem and run my program fine.
At first, I compiled OpenCV myself. Even though all the dlls seemed to be created correctly and there was no build error, I noticed that the header folders are not correctly organized. Therefore, I switched to the superpack binary and tried static linking. There were a lot of undefined symbols at the beginning, so I basically just put everything into VS link options. The number of libraries I had to input to VS was quite absurd, but it is a good way to test if the superpack works.
These are what I use.
opencv_core230d.lib;opencv_calib3d230d.lib;opencv_contrib230d.lib;opencv_features2d230d.lib;opencv_highgui230d.lib;opencv_legacy230d.lib;opencv_ml230d.lib;opencv_imgproc230d.lib;opencv_video230d.lib;libjasperd.lib;libjpegd.lib;libpngd.lib;libtiffd.lib;zlibd.lib;
I also need to input Comctl32.lib to resolve linking error.
I tested my program with static libraries of superpack. Things work fine now.
The headers I used are
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
I do not try using dlls yet, but I can confirm that VS 2010 + OpenCV 2.3 64 bit from the superpack work. I hope you will have some luck with the superpack too.
(Hmm, I can't remember if I put opencv.hpp in the opencv2 folder myself, or if it was there right from the beginning. I did a lot of things to make it work and was a bit confused. But, I believe you can figure this out yourself if there is anything wrong about the header.)
Hope this helps,
Pinyo
You should try making a cycle structure:
#include <iostream>
#include <cv.h>
#include <highgui.h>
using namespace cv;
int main(){
Mat image;
namedWindow( "Gray image", 2 );
while(1){
image = imread( "d://Gaa6P.png", 1 );
imshow( "Gray image", image );
waitKey(0);
}
return 0;
}
Check your firewall. turn off firewall totally. Your antivirus may block the process too.
I had the same problem: cv::exception for memory and this was it's cause.
I'm trying to configure my Visual C++ to use the openCV libraries. I've followed the instructions on OpenCV website http://opencv.willowgarage.com/wiki/VisualC%2B%2B...
// OpenCV_Helloworld.cpp : Defines the entry point for the console application.
// Created for build/install tutorial, Microsoft Visual Studio and OpenCV 2.2.0
#include "stdafx.h"
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
int _tmain(int argc, _TCHAR* argv[])
{
// Open the file.
IplImage *img = cvLoadImage("photo.jpg");
if (!img) {
printf("Error: Couldn't open the image file.\n");
return 1;
}
// Display the image.
cvNamedWindow("Image:", CV_WINDOW_AUTOSIZE);
cvShowImage("Image:", img);
// Wait for the user to press a key in the GUI window.
cvWaitKey(0);
// Free the resources.
cvDestroyWindow("Image:");
cvReleaseImage(&img);
return 0;
}
I have altered the include and library directories in VC++ directories inside the Property Pages, and have added the additional dependencies. However, when I try and load an image with the same header files as the sample code, it says that cvLoadImage is undefined, as is cvNamedWindow
IplImage *img = cvLoadImage("JellyFish.jpg");
Any suggestions as to where I might have my problem?
You might try making sure your Code Generation for your project is Multi-threaded DLL (or Multi-threaded Debug DLL).
You need to configure using CMake. Get OpenCV 2.2 and try the following step by step guide.
http://kaushalsolanki.com/2011/01/compile-and-set-up-opencv-for-visual-studio-2010-with-64-bits-support-ipp-7-0-and-tbb/
I encountered the same error but i finally fixed it
I am using opencv 2.3
what I did was I changed all the additional dependencies
from opencv_core220d.lib to opencv_core231d.lib
we need to change all of the dependencies in the same way
and then i copied all the *.dll files from my bin>>debug folder to
where i had new project that is
helloworld>>helloworld
for example
C:\opencv\build\bin\debug copy all *.dll files to
C:\opencv\Projects\helloworld\helloworld