Pe Dro
Pe Dro

Reputation: 3033

How to start with landmark detector for custom objects?

I am trying to make a landmark detector for a custom object, this panel:

enter image description here

I am going through multiple approaches to it: using heatmaps and regression-based ones.

I tried hands on this Kaggle notebook and found it useful, but has data in grayscale and may not work well as the panel is dark itself.

Is there a well-documented method to do so ?

Upvotes: 1

Views: 591

Answers (1)

burak akdemir
burak akdemir

Reputation: 153

If your purpose is to detect the coordinates of the corners than The methods that you proposed are overkill. You can simply do template matching for each of the corners. Refer to the code below for a rough example

import numpy as np
import cv2 as cv
import matplotlib.pyplot as plt
#%%
src = cv.imread('airMH.jpg')

gray = cv.cvtColor(src,cv.COLOR_BGR2GRAY)
blur=cv.GaussianBlur(gray,(3, 3),1)
templateRightBot = blur[170:205,110:135];
templateLeftBot = blur[150:185,15:50];
templateRightTop = blur[35:75,135:160];
templateLeftTop = blur[30:50,80:105];

#%%
img=src.copy()
w, h = templateLeftTop .shape[::-1]
res = cv.matchTemplate(gray, templateLeftTop, cv.TM_CCOEFF)
min_val, max_val, min_loc, max_loc = cv.minMaxLoc(res)
top_left = max_loc
templateLeftTop = (top_left[0] + w, top_left[1] + h)
cv.rectangle(img,top_left, templateLeftTop, 255, 2)
plt.subplot(2,2,1),plt.imshow(img,cmap = 'gray')
plt.title('LeftTop'), plt.xticks([]), plt.yticks([])

img=src.copy()
w, h = templateRightTop .shape[::-1]
res = cv.matchTemplate(gray, templateRightTop, cv.TM_CCOEFF)
min_val, max_val, min_loc, max_loc = cv.minMaxLoc(res)
top_left = max_loc
templateRightTop = (top_left[0] + w, top_left[1] + h)
cv.rectangle(img,top_left, templateRightTop, 255, 2)
plt.subplot(2,2,2),plt.imshow(img,cmap = 'gray')
plt.title('RightTop'), plt.xticks([]), plt.yticks([])

img=src.copy()
w, h = templateLeftBot .shape[::-1]
res = cv.matchTemplate(gray, templateLeftBot, cv.TM_CCOEFF)
min_val, max_val, min_loc, max_loc = cv.minMaxLoc(res)
top_left = max_loc
templateLeftBot = (top_left[0] + w, top_left[1] + h)
cv.rectangle(img,top_left, templateLeftBot, 255, 2)
plt.subplot(2,2,3),plt.imshow(img,cmap = 'gray')
plt.title('LeftBot'), plt.xticks([]), plt.yticks([])

img=src.copy()
w, h = templateRightBot .shape[::-1]
res = cv.matchTemplate(gray, templateRightBot, cv.TM_CCOEFF)
min_val, max_val, min_loc, max_loc = cv.minMaxLoc(res)
top_left = max_loc
templateRightBot = (top_left[0] + w, top_left[1] + h)
cv.rectangle(img,top_left, templateRightBot, 255, 2)
plt.subplot(2,2,4),plt.imshow(img,cmap = 'gray')
plt.title('RightBot'), plt.xticks([]), plt.yticks([])

here is the output:

output of template matching

about converting image into grayscale, since your images are taken outdoors, you need to normalize them to get rid of the effects of sunlight, etc... so converting images into grayscale kind for serves as normalization. So it does more good than harm.

Upvotes: 1

Related Questions