Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vision.py (ep 5) #4

Closed
asdfsadfasdfg234Fa opened this issue Oct 9, 2020 · 1 comment
Closed

vision.py (ep 5) #4

asdfsadfasdfg234Fa opened this issue Oct 9, 2020 · 1 comment

Comments

@asdfsadfasdfg234Fa
Copy link

File "main.py", line 31, in
points = vision_limestone.find(screenshot, 0.5, 'rectangles')
File "C:\Users\x\Documents\x\lx\vision.py", line 29, in find
result = cv.matchTemplate(haystack_img, self.needle_img, self.method)
cv2.error: OpenCV(4.4.0) C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-52oirelq\opencv\modules\imgproc\src\templmatch.cpp:1163: error: (-215:Assertion failed) (depth == CV_8U || depth == CV_32F) && type == _templ.type() && _img.dims() <= 2 in function 'cv::matchTemplate'

Not sure what's causing this. My own version of the code causes it and then I tried directly copying the file structure and this still happens

@learncodebygaming
Copy link
Owner

This error means that OpenCV doesn't like one of the images you've given to matchTemplate(). Either it's not a valid image, or OpenCV just doesn't like how your image is formatted. So the problem could be anywhere along the chain from when you first capture or load the image, to where you give it to matchTemplate().

Most likely this will be your haystack_img that it has a problem with. When I was working on this project, I saw this error most often when I was calling find() before the window capture had successfully taken a screenshot. This usually happens when the program is first started.

So the first thing to try is adding something like:

if screenshot is None:
        continue

to your main while loop, so it'll only call find() once it has a screenshot.

If that doesn't solve it, I would try saving your screenshot image to a file to confirm it looks how you expect it to. If it looks fine, then there's some sort of conversion you'll need to apply/remove from the image. You can see in WindowCapture get_screenshot() where I've left a comment about a similar error and needing to do a conversion to remove the alpha channel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants