Assertion failed in unknown function

c++, opencv, visual-c++

Solution

As answered by others, make sure the parameter1 in cvtColor is not 1 channel image. check it by type(). it should be `CV_8UC3` and etc.

Put `waitKey` after `imshow`. Image will show up.

I do not know why you are saving leftImg in imreadtest.txt. [ Though it is not making the error.]

Problem

I am using this program to just read and display an image. I dont know why it is showing this odd error: assertion failed `(scn==3 || scn ==4)` in unknown function,file......\src\modules\imgproc\src\color.cpp line 3326 I changed some images, sometimes it runs without error but, even when it runs and everything, it is showing the window but not the image in it. What is wrong? ``` #include "stdafx.h" #include "opencv2/calib3d/calib3d.hpp" #include "opencv2/highgui/highgui.hpp" #include "opencv2/imgproc/imgproc.hpp" using namespace cv; using namespace std; void main() { Mat leftImg,frame=imread("C:\\Users\\user\\Downloads\\stereo_progress.png"); leftImg=imread("C:\\Users\\user\\Downloads\\dm_sl.gif");//add of left camera cvtColor(leftImg,leftImg,CV_BGR2GRAY); imwrite("imreadtest.txt",leftImg); imshow("cskldnsl",leftImg); getchar(); } ```

Original source

Related problems