Vs2008 call opencv2.4.9 imread () function failure Solution

Source: Internet
Author: User

In the past two days, I have been reading the C ++ interface functions of opencv. At the beginning, there was a problem:

A simple image display program cannot run successfully:

#include <opencv2/core/core.hpp>#include <opencv2/highgui/highgui.hpp>#include <string>using std::string;using namespace cv;int main(){string str="E:\\test\\LENA.BMP";Mat img1= imread(str);namedWindow("LENA");imshow("LENA",img1);waitKey();return 1;}

At the beginning, I still suspected that I had not written the code for too long. I forgot to write the absolute path of the file. I checked it and found that the slash \ is a reserved symbol. Therefore, to compile the file correctly, two slashes \ are required \\, there is no error.

If the absolute path is used, imread () memory overflow occurs:


If the image is directly stored in the project directory, the read image is empty:


After an afternoon of tangle, I finally found the problem: Solution: 1. Check whether the libraries added by debug and release are correct.The Internet says that this will happen if the library is not correctly added. debug should have the xxxd. Lib suffix, but my library is correctly added.

Library added by Debug:
Opencv_calib3d249d.lib
Opencv_contrib249d.lib
Opencv_core249d.lib
Opencv_features2d249d.lib
Opencv_flann249d.lib
Opencv_gpu249d.lib
Opencv_highgui249d.lib
Opencv_imgproc249d.lib
Opencv_legacy249d.lib
Opencv_objdetect249d.lib
Opencv_ts249d.lib
Opencv_video249d.lib
Opencv_nonfree249d.lib
Opencv_ocl249d.lib
Opencv_photo249d.lib
Opencv_stitching249d.lib
Opencv_superres249d.lib
Opencv_videostab249d.lib


Database added by release:
Opencv_calib3d249.lib
Opencv_contrib249.lib
Opencv_core249.lib
Opencv_features2d249.lib
Opencv_flann249.lib
Opencv_gpu249.lib
Opencv_highgui249.lib
Opencv_imgproc249.lib
Opencv_legacy249.lib
Opencv_ml249d.lib
Opencv_objdetect249.lib
Opencv_ts249.lib
Opencv_video249.lib
Opencv_nonfree249.lib
Opencv_ocl249.lib
Opencv_photo249.lib
Opencv_stitching249.lib
Opencv_superres249.lib
Opencv_videostab249.lib


2. vs2008 does not support opencv2.4.9

View the path of the included library file and find: D: \ Program Files \ opencv2.4.9 \ build \ x86 \ VC10 \ Lib. I use the VC10 library, opencv2.4.9 does not have the vc9 version. Use vs2010 to create a new project...


Previously, all functions using the C interface were used. It was estimated that there was no major impact. As a result, this problem occurred when using the C ++ interface function, fortunately, this hidden danger was discovered during the debugging of this simple program. Otherwise, it would be troublesome when a large project was created later.

To use opencv2.4.9 on vs2008, use cmake to re-compile a library.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.