Tag Archives: OpenCV

Cmake Compile opencv error: The system is: Windows – 10.0.19042 – AMD64 (Log File)

After clicking configure, an error will be reported by default. Check the log file:

The system is: Windows - 10.0.19042 - AMD64

Reason: the compiler is not selected correctly. You should select the one installed on your computer. For example, the 2019 version I installed is changed to 2019.

Solution: click file->delete cache to reselect the compiler.

v2.error: OpenCV(4.5.5) error: (-215:Assertion failed) npoints > 0 in function ‘cv::drawContours‘

Error Messages: cv2.drawContours(thresh_Contours, cnts, -1, (0, 0, 255), 3)
cv2.error: OpenCV(4.5.5) D:\a\opencv-python\opencv-python\opencv\modules\imgproc\src\drawing.cpp:2502: error: (-215:Assertion failed) npoints > 0 in function ‘cv::drawContours’
Reason: Different Opencv versions cause errors

cnts = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL,
                        cv2.CHAIN_APPROX_SIMPLE)[1]
cv2.drawContours(thresh_Contours, cnts, -1, (0, 0, 255), 3)

Correction method: change “1” to “0”

cnts = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL,
                        cv2.CHAIN_APPROX_SIMPLE)[0]
cv2.drawContours(thresh_Contours, cnts, -1, (0, 0, 255), 3)

Opencv c++ Read Video Error: capture.isOpened() Return false

#include<iostream>
#include<opencv2/opencv.hpp>
using namespace cv;
using namespace std;
int main()
{
    VideoCapture capture;
    Mat frame;
    const string source = "/home/gear/big_disk_c/wangjd/shipintest/789.mp4";
    // frame= capture.open("789.mp4");
    frame= capture.open(source);
    if(!capture.isOpened())
    {
        printf("can not open ...\n");
        return -1;
    }
    printf("1213131\n");
    // namedWindow("output", CV_WINDOW_AUTOSIZE);

    while (capture.read(frame))
    {
        imshow("output", frame);
        waitKey(10);
    }
    capture.release();
    return 0;
}

Reason: Path. I have a permission problem with this server, and it will report an error if I write the full path. And the executable file I generated and the video file are not in the same directory, …/789.mp4 will not be read, only the two put together to read. Later I found out that
The constructor of capture.open() passed in a const string, so I instantiated a const string source first, then I could write the full path, and then passed it in.

const string source = "/home/gear/big_disk_c/wangjd/shipintest/789.mp4";
frame= capture.open(source);

[Solved] cv2.error: OpenCV(4.5.1) XXX\shapedescr.cpp:315: error: (-215:Assertion failed) npoints >= 0 &&……

Error resolution

Error reproduction

Traceback (most recent call last):
  File "D:/pythonProjects/Object_movement/object_movement.py", line 88, in <module>
    c = max(cnts, key=cv2.contourArea)
cv2.error: OpenCV(4.5.1) C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-i1s8y2i1\opencv\modules\imgproc\src\shapedescr.cpp:315: error: (-215:Assertion failed) npoints >= 0 && (depth == CV_32F || depth == CV_32S) in function 'cv::contourArea'

source code

cnts = cv2.findContours(mask.copy(), cv2.RETR_EXTERNAL,
                            cv2.CHAIN_APPROX_SIMPLE)
cnts=cnts[1]

Modified code

cnts, hierarchy = cv2.findContours(mask.copy(), cv2.RETR_EXTERNAL,
                                       cv2.CHAIN_APPROX_SIMPLE)

Error reporting reason

New CV2 Findcontours returns two values. The result of [0] is contour instead of [1]

[Solved] ORB_SLAM3 Compile Error: opencv4.0 not found four

CMake Warning at CMakeLists.txt:33 (find_package):
  Could not find a configuration file for package "OpenCV" that is compatible
  with requested version "4.4".

  The following configuration files were considered but not accepted:

    /usr/share/OpenCV/OpenCVConfig.cmake, version: 3.2.0



CMake Error at CMakeLists.txt:35 (message):
  OpenCV > 4.4 not found.


-- Configuring incomplete, errors occurred!
See also "/home/tys/ORB_SLAM3/build/CMakeFiles/CMakeOutput.log".
make: *** No target specified and no makefile found. Stop.

The content of the error report is as above. I found a solution, and there is a solution available.

LIST(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake_modules)

find_package(OpenCV 4.4)
   if(NOT OpenCV_FOUND)
      message(FATAL_ERROR "OpenCV > 4.4 not found.")
   endif()

Find the above location in CMakeList.txt in the ORB_SLAM3 folder and modify

find_package(OpenCV 4.4), as shown in the following code.

LIST(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake_modules)

find_package(OpenCV 3 REQUIRED)
   if(NOT OpenCV_FOUND)
      message(FATAL_ERROR "OpenCV > 4.4 not found.")
   endif()

Normal, so that the fault can be solved.

[Solved] AttributeError: ‘module‘ object has no attribute ‘CALIB_HAND_EYE_PARK‘

ubuntu18.04 ROS:melodic python2.7

 File "/home/bionic/yuxiangROS_handeye/catkin_ws/src/handeye-calib-master/src/handeye-calib/src/handeye/handeye_calibration_backend_opencv.py", line 29, in HandeyeCalibrationBackendOpenCV
    'Park': cv2.CALIB_HAND_EYE_PARK,
AttributeError: 'module' object has no attribute 'CALIB_HAND_EYE_PARK'
[base_hand_on_eye_calib-1] process has died [pid 15724, exit code 1, cmd /home/bionic/yuxiangROS_handeye/catkin_ws/src/handeye-calib-master/src/handeye-calib/src/handeye/base_hand_on_eye_calib.py __name:=base_hand_on_eye_calib __log:=/home/bionic/.ros/log/600b94f2-660e-11ec-93c4-94c691a2c1c1/base_hand_on_eye_calib-1.log].
log file: /home/bionic/.ros/log/600b94f2-660e-11ec-93c4-94c691a2c1c1/base_hand_on_eye_calib-1*.log
all processes on machine have died, roslaunch will exit
shutting down processing monitor...
... shutting down processing monitor complete

It should be the opencv version

I used the Q2 command and succeeded

Q1.pip install transforms3d
Q2.python -m pip install opencv-contrib-python, and then follow @yangbenbo 's advice, this problem is done(thank you).
Q3.after the two qusetion, Q3 is normal automaticaly.I just want to test the single node to debug(rqt_easy_handeye), thanks for your advice, it works.

[Solved] error: (-215:Assertion failed) size.width>0 && size.height>0 in function ‘imshow‘

Error: cv2.error: OpenCV(4.5.4) /tmp/pip-req-build-w88qv8vs/opencv/modules/highgui/src/window.cpp:1006: error: (-215:Assertion failed) size.width>0 && size.height>0 in function ‘imshow’
Check if there is a problem with the image path:

It is found that None ==> You cannot use “~” to formulate the path, just modify it to the full path:

[Solved] OpenCV VideoWriter Error: FFMPEG: tag ‘MP4V‘ is not supported with codec id 12 and format mp4

1. Problem code

A few months ago, a piece of code could be executed normally. Some of the codes are as follows:

def buildVideoByCV():
    videoMake = cv2.VideoWriter()
    fourcc = cv2.VideoWriter_fourcc(*'MP4V') #https://blog.csdn.net/whudee/article/details/108689420
    fps = 12
    videoMake.open(r"g:\video\lightShowCV.MP4", fourcc, fps, (800,600))

    for t in range(65*fps):
        img = makeframe(t*1.0/fps)
        videoMake.write(img)
        if t%20==0:print(f'\r视频制作进度:{(t*100.0)/(66*fps):4.2f}%',end='')
    videoMake.release()

2. Error message

Error in execution today:

Video production progress: 95.96%OpenCV: FFMPEG: tag 0x5634504d/'MP4V' is not supported with codec id 12 and format 'mp4/MP4 (MPEG-4 Part 14)'
OpenCV: FFMPEG: fallback to use tag 0x7634706d/'mp4v'

3. Solution

Set FourCC = cv2.videowriter_FourCC (*'mp4v') is changed to: FourCC = CV2.Videowriter_FourCC (*'mp4v') , just change the encoded uppercase mp4v to lowercase.

4. Summary

This paper introduces the solution to the error reported by opencv videowriter: ffmpeg: tag ‘mp4v’ is not supported. You only need to replace the code ‘mp4v’ with ‘mp4v’.

[Solved] Android Studio Error: Use of undeclared identifier ‘cv‘

Problem description

This error occurs when I use the opencv3.4.16 official so file in Android studio

Sort by Pvalue from smallest to largest

Change the build.gradle file

Change arguments “- dandroid_stl = C + + _shared”
to arguments “- dandroid_stl = gnustl_shared”

Possible causes:

Opencv3.4.16 officially uses the gun compiler, so it is specified as gnustl_shared

How to Solve Vector Variable Error in sub thread

Once, when using an industrial camera for timing photo recognition, I encountered a situation: at that time, a sub thread was used for timing photo recognition, but after running, it was found that the error of memory overflow was reported when the sub thread was opened, resulting in the collapse of the program. After exclusion, it was found that the vector variable was used in the sub thread. After using the vector variable, the memory is not cleared, resulting in saving. You should use resize to clear the memory.

Program segment with error:

vector<Mat> channels;
split(imgRect, channels);
Mat img = channels.at(0);

Program segments that can operate normally after modification:

vector<Mat> channels;
split(imgRect, channels);
Mat img = channels.at(0);
channels.resize(0);

It is hereby recorded and shared