Tag Archives: opencv

[Solved] Opencv edge detection error: OpenCV(4.1.1) error: (-215:Assertion failed) npoints >= 0 && (depth == CV_32F || depth ==…

cnts = cv2.findContours(edged_image.copy(), cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if imutils.is_cv2() else cnts[1]
cnts = sorted(cnts, key=cv2.contourArea, reverse=True)[:5]

Error:
OpenCV(4.1.1) error: (-215:Assertion failed) npoints >= 0 && (depth == CV_32F || depth == CV_32S) in function ‘cv::contourArea’

Solution:
Wrong operation here:
cnts = cnts[0] if imutils.is_cv2() else cnts[1]
If you still want to use it, you can change it to:
cnts = cnts[1] if imutils.is_cv3() else cnts[0]

 

Opencv learning notes 05 face detection and recognition attributeerror: module ‘CV2’ has no attribute ‘face’

How did “people you might know” find you on social software>>>

1 environment setting:

win10

python 3.6.8

opencv 4.0.1

2 try the best method

In learning face recognition, there is no face attribute in CV2. I found several methods on the Internet, but failed to solve the problem

2.1 method 1

Source: module ‘CV2. CV2’ has no attribute ‘face’

pip install opencv-contrib-python

Restart sublime and still report an error after running

Of course, this failure may be due to the mismatch between opencv and contrib versions

2.2 method 2

Source: opencv3 Python face recognition method face recognition and tagging

Methods:

Will

model = cv2.face.createEigenFaceRecognizer()

Change to

model = cv2.face_EigenFaceRecognizer.create()

According to the error report, it just doesn’t exist this time_ The eigenfacerecognizer property

Of course, the above two can not solve the error, it may be a version problem

3 solutions

3.1 find roots and ask ancestors – Official Website

First, check the opencv website https://docs.opencv.org/4.0.1/

opencv modules stands out

Since there is a problem with the modules of OpenCV, let’s look at the modules directly

note: don’t click modules in the menu bar, just look at the contents of this page; The main reason is that the content you see after clicking is confusing. On the contrary, it doesn’t help much to “open the magic door”

It is not difficult to find that we did not find the face class in the main modules of OpenCV; When we continue to look at extra modules, we find face Ren Du two pulse to get through

It’s really a coincidence. When you open the modules in the menu bar, you will find that all modules (here is a list of all modules:) are listed for up to four pages. Fortunately, face analysis appears on the first page. After clicking it, you will see a detailed explanation of the face class [face analysis]. However, it’s hard to see the true face of Lushan at this time

3.2 solutions

When installing libraries before, I remember that some library files contain contrib, but they have not been installed. Contrib should be related to extra modules

Open the python Extension Pack website https://www.lfd.uci.edu/ ~gohlke/pythonlibs/#opencv,

Find the corresponding version of OpenCV_ python-4.0.1+contrib-cp36-cp36m-win_ Amd64.whl, download install

It’s done

The opencv Python was uninstalled before installation

The installed version is

opencv-python 4.0.1+contrib

4 references

Official website https://docs.opencv.org/4.0.1/index.html

Face analysis website https://docs.opencv.org/4.0.1/db/d7c/group__ face.html

How to compile opencv3.0 (including extra modules) is a good and enlightening topic

https://www.lfd.uci.edu/ ~Gohlke/pythonlibs/#opencvpython third party library file

Module ‘CV2. CV2’ has no attribute ‘face’ this case is not successful, which may be caused by the mismatch between opencv and extend modules

Opencv3 Python face recognition method – face recognition and tagging document describes the reason. It may be that the new version changes the code form in the book, and the author should also spend a lot of effort

Java call opencv face recognition error insufficient out of memory

Opencv is a cross platform computer vision library based on BSD license (open source), which can run on Linux, windows and Mac OS operating systems. It is lightweight and efficient, which is composed of a series of C functions and a small number of C + + classes. It also provides the interfaces of Java, python, ruby, MATLAB and other languages, and realizes many general algorithms in image processing and computer vision

When opencv is called with Java JNI, it is OK to recognize a single picture. When there are a lot of pictures, an error will be reported

OpenCV Error: Insufficient memory (Failed to allocate 411068927 bytes) in cv::OutOfMemoryError, file opencv\modules\core\src\alloc.cpp, line 52 OpenCV Error:

​
        System.out.println("\nRunning Template Matching");

        Mat img = Highgui.imread(inFile);
        Mat templ = Highgui.imread(templateFile);

        ///Create the result matrix
        int result_cols = img.cols() - templ.cols() + 1;
        int result_rows = img.rows() - templ.rows() + 1;
        Mat result = new Mat(result_rows, result_cols, CvType.CV_64FC1);

        ///Do the Matching and Normalize
        Imgproc.matchTemplate(img, templ, result, match_method);
        Core.normalize(result, result, 0, 1, Core.NORM_MINMAX, -1, new Mat());

        ///Localizing the best match with minMaxLoc
        MinMaxLocResult mmr = Core.minMaxLoc(result);

        Point matchLoc;
        if (match_method == Imgproc.TM_SQDIFF || match_method == Imgproc.TM_SQDIFF_NORMED) {
            matchLoc = mmr.minLoc;
        } else {
            matchLoc = mmr.maxLoc;
        }
        
        
        ///Show me what you got
        Core.rectangle(img, matchLoc, new Point(matchLoc.x + templ.cols(),
                matchLoc.y + templ.rows()), new Scalar(0, 255, 0));

        // Save the visualized detection.
        System.out.println("Writing "+ outFile);
        Highgui.imwrite(outFile, img);

​

JNI calls native’s C + + method because of memory overflow, but it didn’t release the object. Display call:

img.release();

templ.release();
result.release();

Solve it. C + + is the trouble of actively releasing referenced objects

Opencv read USB camera select timeout problem

Phenomenon:

Raspberry pie 4B or 3B + with two USB drive free cameras

When the camera is facing the light, it will report time out

The camera doesn’t turn to the light

Question:

Not enough power

Facing the light may trigger the exposure compensation of the USB camera, resulting in higher power

Solution:

Using hub with additional power supply

There is a select timeout error when calling the camera under Linux. It may be that the power supply capability of the port is insufficient when the camera (especially USB2.0 camera) is plugged into the 2.0 interface. If other problems have not been solved, you can see if there is a problem with this port

The last parameter of the select function in v4l2 is timeout, which is used to set the timeout. After the timeout is set, if no file descriptor is available for monitoring, select will wait for the timeout. If the timeout is exceeded, select will return an error

When you encounter a select timeout error, you can’t just consider increasing the timeout time. In fact, this is a temporary solution rather than a permanent solution. It’s impossible to increase the timeout too much. It’s useless to increase the timeout a little. There must be other problems such as transmission blocking. This problem has been bothering us for a long time. Later, I wonder if the port of the USB 2.0 camera is not working. I replaced a 3.0 interface computer, and this problem never happened again. I asked the camera manufacturer about this problem. Their answer is that the transmission and power supply of the USB2.0 camera are integrated, so they are not very stable. When the data transmission and power supply may affect each other, I don’t know about the impact of this, but this issue might as well be used as an additional inspection idea

For reference, Logitech c270 (resolution 720p) needs about 0.2A under the working state. A single USB 2.0 interface is generally conservatively designed with a current of 0.5A and USB 3.0 1a, so it’s no problem to drag two single ports for minimum protection. If your camera is equipped with night vision, the night power will soar. This should be analyzed according to the actual situation, However, this situation can also be solved by USB hub with power supply port

Connecting four cameras is not a big problem, auxiliary power supply head + charger can be done