0

I'm trying to run a program to display an image using opencv but I get the following errors:

file not recognized: File format not recognized
C:\opencv\release\bin\opencv_ffmpeg249_64.dll

error:Id returned 1 exit status
File not found: collect2.exe

.pro file:

QT       += core

QT       -= gui

TARGET = myFirstOpenCVProject
CONFIG   += console
CONFIG   -= app_bundle
CONFIG   -= qt

TEMPLATE = app


SOURCES += main.cpp

INCLUDEPATH += C://opencv//release//install//include

LIBS += C://opencv//release//bin//*.dll

#LIBS += C://opencv//release//lib//*.a

LIBS += -LC://opencv//release//lib -llibopencv_core249 -llibopencv_highgui249 -llibopencv_imgproc249

OTHER_FILES += \
    img.JPG

main.cpp

#include <opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>


int main()
{
        // read an image
        cv::Mat image= cv::imread("img.jpg");
        // create image window named "My Image"
        cv::namedWindow("My Image");
        // show the image on window
        cv::imshow("My Image", image);
        // wait key for 5000 ms
        cv::waitKey(1000);
        return 1;
}

The image(img.jpg) is in the appropriate directory; where the project executable is. I tried removing the dll and the code ran without errors but it did nothing and just showed a shell prompting me to hit return.

enter image description here

6
  • 1
    can you please try to hardcode the full image path (with / or double-backslashes if in windows)? The imread didnt work (wrong path, corrupt file or imread is broken), so the mat you want to display is empty. Commented Apr 29, 2015 at 10:19
  • 1
    please change to cv::waitKey(0); (waits until you press a key) and return 0; (return 1 means error) Commented Apr 29, 2015 at 10:19
  • are you building in debug mode or in release mode? Commented Apr 29, 2015 at 10:20
  • please try imread("img.JPG") according to your proj file Commented Apr 29, 2015 at 10:24
  • Hardcoding the full path worked, i was i release mode. Thanks, could you post an answer for me to accept, also how did you identify the error? Commented Apr 29, 2015 at 10:26

1 Answer 1

1

This line is the problem

LIBS += C://opencv//release//bin//*.dll

This line makes you include all the .dll files that are in the bin folder for OpenCV. You don't want to do this.


You may just be able to remove this line and it will work I am unable to test. Failing that see below


What you want to do is include only the dll files for the code you are using. The matching DLLs for

  • core
  • highgui
  • imgproc

something like this would work for OpenCV 2.4.9 debug (remove the last d for release libs):

LIBS += C://opencv//release//bin//opencv_highgui249d.dll
LIBS += C://opencv//release//bin//opencv_imgproc249d.dll
LIBS += C://opencv//release//bin//opencv_core249d.dll
Sign up to request clarification or add additional context in comments.

5 Comments

do the dlls have to be added at all?
hmm you could be right. It might just be a case of removing the *.dll line completly
I replaced that line with LIBS += -LC://opencv//release//bin -llibopencv_core249 -llibopencv_highgui249 -llibopencv_imgproc249 now the code runs but crashes immediately.
without the error its hard to debug. However if you are building in debug then add d to your libs i.e -llibopencv_core249d
I get no errors or warnings in qt. However the prompt that opens when I run the code gives an opencv error relating to the size and height of the image. Is there a limit to what opencv can open? Sorry I hit enter before I finished typing

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.