opencv_contrib icon indicating copy to clipboard operation
opencv_contrib copied to clipboard

linemod can not found features with mask by Python

Open Yakuho opened this issue 3 years ago • 2 comments

System information (version)
  • OpenCV => 4.6.0
  • Operating System / Platform => Windows 64 Bit
  • Compiler => Visual Studio 2017
  • programming language => python3.8
Detailed description

OpenCV Contrib linemod code When I use opencv-python linemod to run a detector demo, I meet some template and mask trouble!!

import numpy as np
import cv2


detector = cv2.linemod.getDefaultLINE()
colorGradient = detector.getModalities()[0]
template = cv2.imread("template.png", 1)


def show(paddedEnable=0, maskEnable=0):
    global template
    mask = np.ones(template.shape[:2], dtype=np.uint8) * 255
    if paddedEnable:
        template = cv2.copyMakeBorder(template, 100, 100, 100, 100, cv2.BORDER_CONSTANT, 0)
        mask = cv2.copyMakeBorder(mask, 100, 100, 100, 100, cv2.BORDER_CONSTANT, 0)
    if maskEnable:
        quantizedPyramid = colorGradient.process(template, mask)
    else:
        quantizedPyramid = colorGradient.process(template, None)
    retval, templ = quantizedPyramid.extractTemplate()
    for feature in templ.features:
        cv2.circle(template, (feature.x, feature.y), 2, (0, 0, 255), 2)
    cv2.imshow('w1', template)
    cv2.imshow('w2', mask)
    cv2.waitKey(0)


if __name__ == '__main__':
    show(paddedEnable=0, maskEnable=0)
Steps to reproduce

As I know, mask image should be pixel value is 0 or 255, mask image type is uint8 in python, uint8 equal CV_8UC1.

  1. when set maskEnable false, paddedEnable false: Found features perfectly!
  2. when set maskEnable false, paddedEnable true: It is also good.
  3. when set maskEnable true, paddedEnable false: It can not found features???? :(
  4. when set maskEnable false, paddedEnable false: It is also not found :(

In my code, mask was set the full image (all pixel is 255). Normally detector should match the whole image and extract feature, but it didn't. Maybe my understanding of the mask input is wrong?

Issue submission checklist
  • [x] I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
  • [x] I updated to the latest OpenCV version and the issue is still there
  • [x] There is reproducer code and related data files: videos, images, onnx, etc

Yakuho avatar Nov 10 '22 08:11 Yakuho

template.png

Yakuho avatar Nov 10 '22 09:11 Yakuho

in 2025, this problem is still remaining.

Froghahaha avatar Jun 10 '25 16:06 Froghahaha