Ask Your Question
0

imread is not getting identified in visual studio whereas cvloadimage is getting identified in the following code

asked 2018-06-25 01:45:15 -0500

updated 2018-06-25 01:55:13 -0500

berak gravatar image

(code:)

#include<opencv/cv.h>
#include<opencv/highgui.h>

using namespace cv;

int main()
{
    Mat img = cvLoadImage("C:\\opencv2_4_13\\sources\\samples\\data\\fruits.jpg");
    Mat img1;
    cvtColor(img, img1, COLOR_BGR2GRAY);
    imshow("ex", img1);
    cvWaitKey(0);
    return 0;
}
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-06-25 01:57:16 -0500

berak gravatar image

updated 2018-06-25 02:19:41 -0500

you're using the outdated c-api headers, which only contain deprecated functionality.

instead (since you still use the outdated 2.4 version) use:

#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"

also please avoid using any c-api functions:

using namespace cv;
int main()
{
    Mat img = imread("C:\\opencv2_4_13\\sources\\samples\\data\\fruits.jpg");
    if (img.empty()) 
    {
          // add a warning msg, if nessecary
          return -1;
    }
    Mat img1;
    cvtColor(img, img1, COLOR_BGR2GRAY);
    imshow("ex", img1);
    waitKey(0);
    return 0;
}
edit flag offensive delete link more

Comments

When i did that i am getting this runtime error: OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cv::cvtColor, file C:\buildslave64\win64_amdocl\2_4_PackSlave-win32-vc11-shared\opencv\modules\imgproc\src\color.cpp, line 3739

SRIVIDYA gravatar imageSRIVIDYA ( 2018-06-25 02:14:12 -0500 )edit

this means, your image was not read (path wrong) you have to check the outcome of imread(), please see edit.

berak gravatar imageberak ( 2018-06-25 02:17:49 -0500 )edit

the path is correct as, it is running if i use cvloadimage

SRIVIDYA gravatar imageSRIVIDYA ( 2018-06-25 02:23:02 -0500 )edit

then please check, if you're linking opencv debug libs to a release project (or the other way round)

(again, a more modern opencv version would not allow you to do this)

berak gravatar imageberak ( 2018-06-25 02:56:28 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2018-06-25 01:45:15 -0500

Seen: 159 times

Last updated: Jun 25 '18