question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Web service (flask) gives "error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'"

See original GitHub issue
  • face_recognition version: latest
  • Python version: 3.6
  • Operating System: Ubuntu

Description

I tried to make a simple project from your code where people upload an image and it compares to the encodings.pickle where it could recognize people faces. I’m using flask for the framework, xampp and postman to test the web service.

I already went all over the google, common issues example, your web_service_example.py and found related, but not similar, issues #599

What went wrong:

When I tried to run the code and tested it by uploading an image from postman, it returns an error

  File "...", line 56, in recog
    rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
cv2.error: OpenCV(4.0.0-beta) /.../opencv/modules/imgproc/src/color.cpp:181: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'

Here’s the code

def recog(self, photo):
        data = pickle.loads(open("encodings.pickle", "rb").read())
        photo = str(photo)
        image = cv2.imread(photo)
        rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

        boxes = face_recognition.face_locations(rgb, model="cnn")
        encodings = face_recognition.face_encodings(rgb, boxes)

        names = []

        for encoding in encodings:
            matches = face_recognition.compare_faces(data("encodings.pickle", "wb"), encoding)
            name = "Unknown"

            if True in matches:
                matchedIdxs = [i for (i, b) in enumerate(matches) if b]
                counts = {}
                for i in matchedIdxs:
                    name = data["names"][i]
                    counts[name] = counts.get(name, 0) + 1
                name = max(counts, key=counts.get)
            names.append(name)
        return name

Any help will be appreciated. I am completely clueless just like #599

Thank you for the support

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
ageitgeycommented, Nov 30, 2018

That error message is basically a really complicated way of it complaining that the image you passed to cv2.cvtColor() was empty. So the problem is that earlier in your program cv2.imread() failed to load a valid image from the data that you passed in to it.

So either you didn’t read the data from the request correctly, you didn’t post the image data correctly with postman, or something with the image data is getting mangled along the way.

0reactions
Divya-14commented, Jun 13, 2020

That error message is basically a really complicated way of it complaining that the image you passed to cv2.cvtColor() was empty. So the problem is that earlier in your program cv2.imread() failed to load a valid image from the data that you passed in to it.

So either you didn’t read the data from the request correctly, you didn’t post the image data correctly with postman, or something with the image data is getting mangled along the way.

@ageitgey , Thank you so much! I was struggling with that problem since 4 hours. Means a lot!

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is the reason for this error? (-215:Assertion failed) !_src ...
You get the error when you are attempting to use the cv2.cvtColor() method on an empty image. Observe: >>> import cv2 >>> import...
Read more >
error: (-215:Assertion failed) !_src.empty() in function 'cv
How to solve error : (- 215:Assertion failed ) !_src. empty () in function 'cv:: cvtColor ' in opencv is shown.
Read more >
Why do I get the following error after and hour of operation cv2 ...
Things work fine for 30 minutes to an hour, then I get the following error: ``` (-215:Assertion failed) !_src.empty() in function 'cvtColor'
Read more >
error: opencv(4.6.0) /io/opencv/modules/imgproc/src/color.cpp ...
cpp:182: error: (-215:assertion failed) !_src.empty() in function 'cv::cvtcolor'. Try Giving Full Path ...
Read more >
Face Recognition with Python, in Under 25 Lines of Code
Thank you. Free Bonus: Click here to get the Python Face Detection & OpenCV Examples Mini-Guide that shows you practical code examples of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found