- fixed masking
- no image blur for processed image
This commit is contained in:
+12
-13
@@ -18,7 +18,7 @@ COLOR_CIRCLE = (0, 255, 0)
|
|||||||
TEMPLATE_MATCH_OVERLAP = 0
|
TEMPLATE_MATCH_OVERLAP = 0
|
||||||
|
|
||||||
CONSOLE_DEBUG = False
|
CONSOLE_DEBUG = False
|
||||||
IMAGE_DEBUG = True
|
IMAGE_DEBUG = False
|
||||||
DO_TRACKING = False
|
DO_TRACKING = False
|
||||||
|
|
||||||
|
|
||||||
@@ -158,7 +158,7 @@ class CornerTracker:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def image_process(_image: np.array):
|
def image_process(_image: np.array):
|
||||||
result = cv2.cvtColor(_image, cv2.COLOR_BGR2GRAY)
|
result = cv2.cvtColor(_image, cv2.COLOR_BGR2GRAY)
|
||||||
result = cv2.GaussianBlur(result, (9, 9), 0)
|
# result = cv2.GaussianBlur(result, (9, 9), 0)
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@@ -175,10 +175,9 @@ class CornerTracker:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
tracking_img = image_crop(_image, bb)
|
tracking_img = image_crop(_image, bb)
|
||||||
image_process_local = CornerTracker.image_process(tracking_img)
|
|
||||||
tracking_mask = image_crop(_mask, bb)
|
tracking_mask = image_crop(_mask, bb)
|
||||||
masked_tracking_img = tracking_img.copy()
|
CornerTracker.mask_apply(tracking_img, tracking_mask)
|
||||||
CornerTracker.mask_apply(masked_tracking_img, tracking_mask)
|
image_processed_local = CornerTracker.image_process(tracking_img)
|
||||||
|
|
||||||
self.corner_matcher_list = []
|
self.corner_matcher_list = []
|
||||||
self.tracking_bb = bb
|
self.tracking_bb = bb
|
||||||
@@ -188,11 +187,11 @@ class CornerTracker:
|
|||||||
count = 1
|
count = 1
|
||||||
while True:
|
while True:
|
||||||
print(f"Add Corner {count}")
|
print(f"Add Corner {count}")
|
||||||
matching_tpl_bb = cv2.selectROI("Matcher Reference", masked_tracking_img, fromCenter=True, showCrosshair=True)
|
matching_tpl_bb = cv2.selectROI("Matcher Reference", tracking_img, fromCenter=True, showCrosshair=True)
|
||||||
if bbox_center(matching_tpl_bb) == (0, 0):
|
if bbox_center(matching_tpl_bb) == (0, 0):
|
||||||
break
|
break
|
||||||
|
|
||||||
matching_tpl_img = image_crop(image_process_local.copy(), matching_tpl_bb)
|
matching_tpl_img = image_crop(image_processed_local, matching_tpl_bb)
|
||||||
self.corner_matcher_list.append(Corner(matching_tpl_img, matching_tpl_bb, name=f"Corner-{count}"))
|
self.corner_matcher_list.append(Corner(matching_tpl_img, matching_tpl_bb, name=f"Corner-{count}"))
|
||||||
corner_list.append(bbox_center(matching_tpl_bb))
|
corner_list.append(bbox_center(matching_tpl_bb))
|
||||||
|
|
||||||
@@ -215,10 +214,10 @@ class CornerTracker:
|
|||||||
self.tracker.init(_image, self.tracking_bb)
|
self.tracker.init(_image, self.tracking_bb)
|
||||||
|
|
||||||
print(corner_list)
|
print(corner_list)
|
||||||
cv2.imshow("image_process_local", image_process_local)
|
cv2.imshow("image_process_local", image_processed_local)
|
||||||
|
|
||||||
# Refine initial corners and store them as reference
|
# Refine initial corners and store them as reference
|
||||||
corners_local = self._corner_refine(image_process_local, corners=corner_list)
|
corners_local = self._corner_refine(image_processed_local, corners=corner_list)
|
||||||
|
|
||||||
# Transform corners to global
|
# Transform corners to global
|
||||||
self.corner_ref = []
|
self.corner_ref = []
|
||||||
@@ -242,18 +241,18 @@ class CornerTracker:
|
|||||||
return self._match(_image_processed_local, _image_anno, _image_local.copy())
|
return self._match(_image_processed_local, _image_anno, _image_local.copy())
|
||||||
|
|
||||||
def _match(self, _image: np.array, _image_anno: np.array, tracking_anno):
|
def _match(self, _image: np.array, _image_anno: np.array, tracking_anno):
|
||||||
corners_raw = []
|
corner_list = []
|
||||||
for _ct in self.corner_matcher_list:
|
for _ct in self.corner_matcher_list:
|
||||||
matcher_bbox_local, matcher = _ct.process(_image)
|
matcher_bbox_local, matcher = _ct.process(_image)
|
||||||
|
|
||||||
# Draw path
|
# Draw path
|
||||||
corner = bbox_center(matcher_bbox_local)
|
corner = bbox_center(matcher_bbox_local)
|
||||||
corners_raw.append(corner)
|
corner_list.append(corner)
|
||||||
|
|
||||||
self._debug(_image_anno, tracking_anno, matcher_bbox_local)
|
self._debug(_image_anno, tracking_anno, matcher_bbox_local)
|
||||||
|
|
||||||
# refine corners
|
# refine corners
|
||||||
corners_local = self._corner_refine(_image, corners_raw)
|
corners_local = self._corner_refine(_image, corner_list)
|
||||||
|
|
||||||
# Transform corners to global
|
# Transform corners to global
|
||||||
corners_refined = []
|
corners_refined = []
|
||||||
@@ -284,7 +283,7 @@ class CornerTracker:
|
|||||||
# show refined corners
|
# show refined corners
|
||||||
for _i in range(0, corners_refined.shape[0]):
|
for _i in range(0, corners_refined.shape[0]):
|
||||||
self._print(f" -- Corner Reference [{i}] {self.corner_ref[_i]}")
|
self._print(f" -- Corner Reference [{i}] {self.corner_ref[_i]}")
|
||||||
self._print(f" -- Corner coarse [{i}] {corners_raw[_i]}")
|
self._print(f" -- Corner coarse [{i}] {corner_list[_i]}")
|
||||||
self._print(f" -- Corner fine [{i}] {corners_refined[_i]}")
|
self._print(f" -- Corner fine [{i}] {corners_refined[_i]}")
|
||||||
self._print(f" -- Corner distance [{i}] {corners_refined[_i] - self.corner_ref[_i]}")
|
self._print(f" -- Corner distance [{i}] {corners_refined[_i] - self.corner_ref[_i]}")
|
||||||
cv2.circle(_image_anno, (int(corners_refined[_i, 0] + 0.5), int(corners_refined[_i, 1] + 0.5)), 4, COLOR_CIRCLE)
|
cv2.circle(_image_anno, (int(corners_refined[_i, 0] + 0.5), int(corners_refined[_i, 1] + 0.5)), 4, COLOR_CIRCLE)
|
||||||
|
|||||||
Reference in New Issue
Block a user