I try to show an Image with the OpenCV-function 'imshow()'.
cv::Mat im = cv::imread("/home/franek/Schreibtisch/image.jpg",cv::IMREAD_GRAYSCALE);
cv::imshow("original", im);
Now it tells me:
OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cvtColor, file /build/opencv-L2vuMj/opencv-3.2.0+dfsg/modules/imgproc/src/color.cpp, line 9716
terminate called after throwing an instance of 'cv::Exception'
what(): /build/opencv-L2vuMj/opencv-3.2.0+dfsg/modules/imgproc/src/color.cpp:9716: error: (-215) scn == 3 || scn == 4 in function cvtColor
When I replace cv::IMREAD_GRAYSCALE with cv::IMREAD_COLOR, the picture is shown and everything is fine. But I need a grayscale image.
Edit: the whole code:
cv::namedWindow("original", cv::WINDOW_GUI_EXPANDED);
cv::namedWindow("grayScale", cv::WINDOW_GUI_EXPANDED);
cv::namedWindow("cornerImage", cv::WINDOW_GUI_EXPANDED);
cv::startWindowThread();
cv::Mat im = cv::imread("/home/franek/Schreibtisch/image.jpg", cv::IMREAD_COLOR);
cv::imshow("original", im);
cv::waitKey(0);
cv::Mat img = cv::imread("/home/franek/Schreibtisch/image.jpg", cv::IMREAD_GRAYSCALE);
cv::imshow("grayScale", img);
cv::waitKey(0);
edit edit:
with ldd i found out the dependencies:
libopencv_imgcodecs.so.3.2 => /usr/lib/x86_64-linux-gnu/libopencv_imgcodecs.so.3.2 (0x00007f2ba95d0000)
libopencv_imgproc.so.3.2 => /usr/lib/x86_64-linux-gnu/libopencv_imgproc.so.3.2 (0x00007f2ba8d77000)
libopencv_core.so.3.2 => /usr/lib/x86_64-linux-gnu/libopencv_core.so.3.2 (0x00007f2ba893c000)
libopencv_highgui.so.4.1 => /usr/local/lib/libopencv_highgui.so.4.1 (0x00007f2ba8724000)
libopencv_imgcodecs.so.4.1 => /usr/local/lib/libopencv_imgcodecs.so.4.1 (0x00007f2ba7e72000)
libopencv_imgproc.so.4.1 => /usr/local/lib/libopencv_imgproc.so.4.1 (0x00007f2ba557e000)
libopencv_core.so.4.1 => /usr/local/lib/libopencv_core.so.4.1 (0x00007f2ba429b000)
Is that the solution? The core and the highui aren't the same version...
解决方案
I found the solution,
the Problem was, that my Code depends in another function from < this is a ROS Specific lib.
This lib uses Opencv 2.3. I head to use a fork, where someone ported this lib to OpenCV 4 here. Now the whole thing works just fine!