Tag Archives: OpenCV

[Solved] Cmake compile opencv open-source project Error: but it set OpenCV_FOUND to FALSE so package “OpenCV” is considered to be…


Recently, cmake encountered the following problems when compiling a C + + open source project configured with OpenCV environment:

CMake Warning at D:/opencv4/OpenCVConfig.cmake:176 (message):
  Found OpenCV Windows Pack but it has no binaries compatible with your

  You should manually point CMake variable OpenCV_DIR to your build of OpenCV
Call Stack (most recent call first):
  CMakeLists.txt:13 (find_package)

CMake Error at CMakeLists.txt:13 (find_package):
  Found package configuration file:


  but it set OpenCV_FOUND to FALSE so package "OpenCV" is considered to be

So I checked all the methods online, which are basically divided into two categories: one is to modify cmakeLis.txt document. The other is to change the OpenCV version or vs version. But They are not working for me. Finally, I accidentally found that x64 was not selected in configure, and x86 was selected by default. After x64 was selected, the compilation was successful.


[Solved] Opencv Call yolov3 Error: IndexError: invalid index to scalar variable

Call the weight file of yolov3 with OpenCV to obtain the names of the three scale output layers and report an error

ln = [ln[i[0] - 1] for i in net.getUnconnectedOutLayers()]

Error reporting
indexerror: invalid index to scalar variable

This code was a few years ago. It may be a problem with the version. Now it will report an error

Remove [0] and modify as below:

ln = [ln[i - 1] for i in net.getUnconnectedOutLayers()]

[Solved] OpenCV Train the class Error: Bad argument & Error: Insufficient memory

OpenCV(3.4.1) Error: Bad argument (Can not get new positive sample. The most possible reason is insufficient count of samples in given vec-file.
) in CvCascadeImageReader::PosReader::get, file


Solution: reduce the number of positive samples

opencv_traincascade.exe -data data_2 -vec positives.vec -bg bg.txt -numPos 350 -numNeg 1963 -mem 8192 -numStages 20 -w 20 -h 20

Here, you can reduce the numpos value

OpenCV(3.4.1) Error: Insufficient memory (Failed to allocate 782736980 bytes) in cv::OutOfMemoryError, file C:\application\opencv\opencv\sources\modules\core\src\alloc.cpp, line 55


Solution: increase memory

Here, increase the value of -mem and decrease the value of numPos

Summary: these two errors mainly lie in that the value of the number of positive samples for each level of training is too large. Numpos must be less than the total number of positive samples. Modifying MEM value only improves the running speed

Raspberry pie Use PCA9685() Error: [Errno 121] Remote I/O error

After I install pca9685() according to the online method, the following errors will appear in the operation.

>>> pwm = Adafruit_PCA9685.PCA9685()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'Adafruit_PCA9685' is not defined
>>> import Adafruit_PCA9685
>>> pwm = Adafruit_PCA9685.PCA9685()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.7/dist-packages/Adafruit_PCA9685-1.0.1-py3.7.egg/Adafruit_PCA9685/PCA9685.py", line 75, in __init__
    self.set_all_pwm(0, 0)
  File "/usr/local/lib/python3.7/dist-packages/Adafruit_PCA9685-1.0.1-py3.7.egg/Adafruit_PCA9685/PCA9685.py", line 111, in set_all_pwm
    self._device.write8(ALL_LED_ON_L, on & 0xFF)
  File "/usr/local/lib/python3.7/dist-packages/Adafruit_GPIO-1.0.4-py3.7.egg/Adafruit_GPIO/I2C.py", line 116, in write8
    self._bus.write_byte_data(self._address, register, value)
  File "/usr/local/lib/python3.7/dist-packages/Adafruit_PureIO-1.1.9-py3.7.egg/Adafruit_PureIO/smbus.py", line 327, in write_byte_data
OSError: [Errno 121] Remote I/O error


But the premise of this method is to have the Adafruit_PCA9685 file under the path /usr/local/lib/python3.7/dist-packages/”, if there is one, use the above method

My Raspberry Pi is 4B, there are three .egg files in the above path, Adafruit_PCA9685 is placed in it, as shown below

Select the middle of the Adafruit_PCA9685 .egg file, there will be PCA9685.py file, just create PCA9685.py under raspberry home/pi/ and paste the contents of the previous PCA9685.py into the newly created file, import the code to import PCA9685 instead of not import Adafruit_PCA9685

import PCA9685

Open the PCA9685 file and find that it needs to import the I2C.py file (I forgot to take a screenshot), then open the first one under the /usr/local/lib/python3.7/dist-packages/ path

Paste the contents of I2C.py and Plaform.py inside this file into a new I2C.py and Plaform.py file under home/pi, then open the PCA9685.py file in this directory and change the imported I2C in the middle position, it seems to be form Adafurit_GPIO import I2C as I2C directly to import I2C.

Then open the I2C file, found that you need to import Plaform.py, the same operation, change the previous import to import Plaform can be, as shown, and finally in the directory I2C.py PCA9685.py and Plaform.py file

You can write it directly in the raspberry pie file

import PCA9685
pwm = PCA9685.PCA9685()

See if it’s successful. I’m successful.

[Solved] Python pytesseract(tesseract OCR) Error: TesseractNotFoundError

Error when running code

Use PIP install pytesseract

pip install tesseract

It still doesn’t work after installation. The same error is reported

Subsequent error finding:

Testseract-ocr is not installed

OCR (Optical Character Recognition): Optical Character Recognition, which refers to the process of analyzing, recognizing, and acquiring text in image files.
Tesseract: An open source OCR recognition engine. The initial Tesseract engine was developed by HP Labs, and later contributed to the open source software industry, and was later improved by Google to eliminate bugs, optimize, and re-release.

http://digi.bib.uni-mannheim.de/tesseract/tesseract-ocr-setup-4.00.00dev.exe Can be downloaded

After installation, add before the error code

pytesseract.pytesseract.tesseract_cmd = 'E:\\software\\Tesseract-OCR\\tesseract.exe'

This is followed by the path to install Tesseract-ocr

Successfully solved.

[Solved] error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows,

Error return

terminate called after throwing an instance of 'cv::Exception'
  what():  OpenCV(3.4.3) /home/chen/Downloads/opencv-3.4.3/modules/highgui/src/window.cpp
  :632: error: (-2: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 function 

Aborted (core dumped)

Error resolution

Execute the command according to the solution given by the system

sudo apt-get install libgtk2.0-dev
sudo apt-get install pkg-config

It doesn’t solve the problem

Cause of problem

The problem is that there is a problem with the compilation configuration when installing opencv
I execute cmake…
and the correct command is



Locate the folder where opencv is installed

cd /home/chen/Downloads/opencv-3.4.3
mkdir release
cd release
sudo make
sudo make install 


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.drawContours(thresh_Contours, cnts, -1, (0, 0, 255), 3)

Correction method: change “1” to “0”

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

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

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);
        printf("can not open ...\n");
        return -1;
    // namedWindow("output", CV_WINDOW_AUTOSIZE);

    while (capture.read(frame))
        imshow("output", frame);
    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,

Modified code

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

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.


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

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.


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

Normal, so that the fault can be solved.