0

Here is the error message:

error: (-215:Assertion failed) (depth == CV_8U || depth == CV_32F) && type == _templ.type() && _img.dims() <= 2 in function 'cv::matchTemplate'

This is the function that the error occurred in, in line result = cv.matchTemplate(biome_img, self.husk_image, self.method)

def find(self, biome_img, threshold=0.5, debug_mode=None):
    result = cv.matchTemplate(biome_img, self.husk_image, self.method)

    locations = np.where(result >= threshold)
    locations = list(zip(*locations[::-1]))

    rectangles = []
    for loc in locations:
        rect = [int(loc[0]), int(loc[1]), self.img_w, self.img_h]

        rectangles.append(rect)
        rectangles.append(rect)

    rectangles, weights = cv.groupRectangles(rectangles, groupThreshold=1, eps=0.5)

This is how I called the function:

while True:
    screenshot = wincap.window_capture()
    points = visionObject.find(screenshot, 0.5, 'rectangles')

I've tried changing them to uint8 and float32 but it didn't work.

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
  • Both images must be the same in either uint8 or float32. Also the two images must have the same dtype. They must be the same as either 1 or 3 channels. Also the template must not be larger than the image. Always check your shape and dtype on both images. – fmw42 Aug 20 '22 at 20:12
  • Does this answer your question? [Python, opencv matchtemplate error](https://stackoverflow.com/questions/48818032/python-opencv-matchtemplate-error) – Christoph Rackwitz Aug 20 '22 at 20:33
  • please review [ask]. you _should_ disclose that you're trying to "automate" Minecraft. – Christoph Rackwitz Aug 20 '22 at 20:34

0 Answers0