use refined corners (Zwischenstand)
This commit is contained in:
@@ -1,10 +1,26 @@
|
|||||||
import cv2
|
import cv2
|
||||||
import sys
|
import sys
|
||||||
import imutils as im
|
import imutils as im
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
from util import bbox_extend, bbox_round, image_crop, to_rect, bbox_add_position, bbox_center
|
from util import bbox_extend, bbox_round, image_crop, to_rect, bbox_add_position, bbox_center
|
||||||
from ocv_corner_tracker import CornerTracker
|
from ocv_corner_tracker import CornerTracker
|
||||||
|
|
||||||
|
|
||||||
|
def refine_corner(src_gray, corners):
|
||||||
|
# Set the needed parameters to find the refined corners
|
||||||
|
winSize = (5, 5)
|
||||||
|
zeroZone = (-1, -1)
|
||||||
|
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TermCriteria_COUNT, 40, 0.001)
|
||||||
|
|
||||||
|
# Calculate the refined corner locations
|
||||||
|
corners = cv2.cornerSubPix(src_gray, corners, winSize, zeroZone, criteria)
|
||||||
|
|
||||||
|
# Write them down
|
||||||
|
for i in range(corners.shape[0]):
|
||||||
|
print(" -- Refined Corner [", i, "] (", corners[i, 0, 0], ",", corners[i, 0, 1], ")")
|
||||||
|
|
||||||
|
|
||||||
COLOR_TRACKER = (0, 255, 0)
|
COLOR_TRACKER = (0, 255, 0)
|
||||||
COLOR_TRACKER_EXT = (0, 255, 255)
|
COLOR_TRACKER_EXT = (0, 255, 255)
|
||||||
COLOR_MATCHER = (0, 0, 255)
|
COLOR_MATCHER = (0, 0, 255)
|
||||||
@@ -76,6 +92,7 @@ while True:
|
|||||||
|
|
||||||
if ok:
|
if ok:
|
||||||
if mode:
|
if mode:
|
||||||
|
corners = []
|
||||||
for ct in ct_list:
|
for ct in ct_list:
|
||||||
matcher_bbox_local, matcher = ct.process(crop)
|
matcher_bbox_local, matcher = ct.process(crop)
|
||||||
matcher_top_left_local, matcher_bottom_right_local = to_rect(bbox_round(matcher_bbox_local))
|
matcher_top_left_local, matcher_bottom_right_local = to_rect(bbox_round(matcher_bbox_local))
|
||||||
@@ -95,11 +112,14 @@ while True:
|
|||||||
|
|
||||||
# Draw path
|
# Draw path
|
||||||
line_to = bbox_center(matcher_bbox)
|
line_to = bbox_center(matcher_bbox)
|
||||||
|
corners.append([line_to])
|
||||||
ct.path_add(line_to)
|
ct.path_add(line_to)
|
||||||
|
|
||||||
for p in ct.path:
|
for p in ct.path:
|
||||||
cv2.line(image_anno, p['from'], p['to'], (0, 0, 255), 2)
|
cv2.line(image_anno, p['from'], p['to'], (0, 0, 255), 2)
|
||||||
|
|
||||||
|
refine_corner(cv2.cvtColor(image, cv2.COLOR_BGR2GRAY), np.array(corners, dtype=np.float32))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Perform template match operations
|
# Perform template match operations
|
||||||
crop_scaled = im.resize(crop.copy(), IMG_SCALE_UP * crop.shape[1], IMG_SCALE_UP * crop.shape[0])
|
crop_scaled = im.resize(crop.copy(), IMG_SCALE_UP * crop.shape[1], IMG_SCALE_UP * crop.shape[0])
|
||||||
@@ -159,4 +179,3 @@ while True:
|
|||||||
k = cv2.waitKey(-1) & 0xff
|
k = cv2.waitKey(-1) & 0xff
|
||||||
if k == 27:
|
if k == 27:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user