Showing posts with label openCV. Show all posts
Showing posts with label openCV. Show all posts

Tuesday, 19 November 2019

openCV Troubleshooting (2) : error: ‘CV_LOAD_IMAGE_GRAYSCALE’ was not declared in this scope


This is due to different versions of openCV. Things got update to different names.

Didn't work:
image1=  cv::imread("test.bmp", CV_LOAD_IMAGE_GRAYSCALE);

Didn't work:
image1=  cv::imread("test.bmp", IMREAD_GRAYSCALE);

WORKED!!!!!
image1=  cv::imread("test.bmp", cv::ImreadModes::IMREAD_GRAYSCALE);


ref:
https://stackoverflow.com/questions/27424285/cv-load-image-grayscale-is-not-definedpy
https://stackoverflow.com/questions/22547416/open-cv-flags-dont-work

openCV Troubleshooting (1) : undefined reference to `cv::xxxx`


I am compiling openCV project with cmake and I am getting errors like:

test.cpp:(.text+0xc0): undefined reference to `cv::imread(std::string const&, int)'
test.cpp:(.text+0x11f): undefined reference to `cv::_OutputArray::_OutputArray(cv::Mat&)'
test.cpp:(.text+0x138): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
test.cpp:(.text+0x158): undefined reference to `cv::cvtColor(cv::_InputArray const&, cv::_OutputArray const&, int, int)'
test.cpp:(.text+0x180): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'

The following compiling script won't cause the issue.
g++ -o test_1 test_1.cpp `pkg-config opencv --cflags --libs`

But to fix cmake compile, we need to add the following red line to CMakeList.txt.

cmake_minimum_required(VERSION 2.8)
project( DisplayImage )
find_package( OpenCV REQUIRED )
add_executable( DisplayImage DisplayImage.cpp )
target_link_libraries( DisplayImage ${OpenCV_LIBS} )


ref:

Sunday, 14 July 2019

openCV Troubleshooting (0): error: (-215:Assertion failed) !empty() in function 'detectMultiScale'

Trying to compile some example code (in Python) from the internet and got the following error:

Traceback (most recent call last):
  File "main.py", line 16, in <module>
    img = drawFaces(img)
  File "/home/boris/facedetect_example/example2/OpenCV-demo-master/Video-FaceDetection/face_detection.py", line 26, in drawFaces
    faces = detectFaces(img)
  File "/home/boris/facedetect_example/example2/OpenCV-demo-master/Video-FaceDetection/face_detection.py", line 18, in detectFaces
    faces = face_cascade.detectMultiScale(gray, 1.2, 5)
cv2.error: OpenCV(4.1.0) /home/boris/workspace/opencv-4.1.0/modules/objdetect/src/cascadedetect.cpp:1658: error: (-215:Assertion failed) !empty() in function 'detectMultiScale'

It turns out the cascade XML or file is missing or the path to it is incorrect or the create_capture path is incorrect. Of course, this is someone else's code.

Updated this line:
face_cascade = cv2.CascadeClassifier("/home/aaaaa/OpenCV-demo/opencv-data/haarcascades/haarcascade_frontalface_default.xml")

To 
face_cascade = cv2.CascadeClassifier("/usr/share/opencv/haarcascades/haarcascade_frontalface_default.xml")

Everything works now.


ref:
https://stackoverflow.com/questions/30508922/error-215-empty-in-function-detectmultiscale

Friday, 23 March 2018

OpenCV Helloworld Trouble


Just want to quickly do an openCV helloworld:

#include <iostream>
#include <opencv2/opencv.hpp>

using namespace std;
using namespace cv;

int main()
{
Mat srcImage = imread("lena.jpg");
imshow("image",srcImage);

waitKey(0);

return 0;
}

Compile:
g++ `pkg-config opencv --cflags` opencv.cpp -o opencv `pkg-config opencv --libs` 

but I got this error:
OpenCV Error: Unspecified error (The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script) in cvShowImage, file /home/boris/Softwares/openCV/opencv/modules/highgui/src/window.cpp, line 611 terminate called after throwing an instance of 'cv::Exception' what(): /home/boris/Softwares/openCV/opencv/modules/highgui/src/window.cpp:611: error: (-2) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function cvShowImage

Something is wrong with QT?

sudo apt-get install libqt4-dev
cmake -D WITH_QT=ON ..
make
sudo make install

ref:
https://stackoverflow.com/questions/14655969/opencv-error-the-function-is-not-implemented
https://blog.csdn.net/keith_bb/article/details/52864851




Thursday, 22 March 2018

Just Installed openCV


Error:
./opencv: error while loading shared libraries: libopencv_highgui.so.3.3: cannot open shared object file: No such file or directory

$ sudo ldconfig


ref:
https://github.com/pjreddie/darknet/issues/382