Ask Your Question

postlude's profile - activity

2019-11-19 07:27:32 -0600 commented question How to exclude outliers from detected Orb features?

@supra56 Here are links to the exact images used in the example: https://www.dropbox.com/s/jmvm2d1w9npzfg3/box_in_scene.

2019-11-19 03:31:35 -0600 commented answer How to exclude outliers from detected Orb features?

@berak out-of-interest, how would I approach finding a cluster centre if I wanted to do that? Would kmeans be overkill?

2019-11-19 03:30:09 -0600 commented answer How to exclude outliers from detected Orb features?

@berak OK, thanks! I assumed that crossCheck=True with dmatches = sorted and e.g. matches[:10] would work, but I just tr

2019-11-19 03:28:12 -0600 marked best answer How to exclude outliers from detected Orb features?

I am using the approach shown below (see bottom of post) to detect an object within a video stream.

As can be seen from the image below (red arrows) I get a number of false points / outliers outside the detected area, especially if I move the detected object. What I would like to do is draw a rectangle around the main cluster of points as returned by cv2.perspectiveTransform(), excluding the outlying points. What is the best way to achieve this?

UPDATE: I have updated the image below to hopefully show more clearly what I'm trying to achieve

image description

#!/usr/bin/python3
# 2017.11.26 23:27:12 CST

## Find object by orb features matching

import numpy as np
import cv2
imgname = "box.png"          # query image (small object)
imgname2 = "box_in_scene.png" # train image (large scene)

MIN_MATCH_COUNT = 4

## Create ORB object and BF object(using HAMMING)
orb = cv2.ORB_create()
img1 = cv2.imread(imgname)
img2 = cv2.imread(imgname2)

gray2 = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY)
gray1 = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)

## Find the keypoints and descriptors with ORB
kpts1, descs1 = orb.detectAndCompute(gray1,None)
kpts2, descs2 = orb.detectAndCompute(gray2,None)

## match descriptors and sort them in the order of their distance
bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)
matches = bf.match(descs1, descs2)
dmatches = sorted(matches, key = lambda x:x.distance)

## extract the matched keypoints
src_pts  = np.float32([kpts1[m.queryIdx].pt for m in dmatches]).reshape(-1,1,2)
dst_pts  = np.float32([kpts2[m.trainIdx].pt for m in dmatches]).reshape(-1,1,2)

## find homography matrix and do perspective transform
M, mask = cv2.findHomography(src_pts, dst_pts, cv2.RANSAC,5.0)
h,w = img1.shape[:2]
pts = np.float32([ [0,0],[0,h-1],[w-1,h-1],[w-1,0] ]).reshape(-1,1,2)
dst = cv2.perspectiveTransform(pts,M)

## draw found regions
img2 = cv2.polylines(img2, [np.int32(dst)], True, (0,0,255), 1, cv2.LINE_AA)
cv2.imshow("found", img2)

## draw match lines
res = cv2.drawMatches(img1, kpts1, img2, kpts2, dmatches[:20],None,flags=2)

cv2.imshow("orb_match", res);

cv2.waitKey();cv2.destroyAllWindows()
2019-11-19 03:28:12 -0600 received badge  Scholar (source)
2019-11-19 03:04:09 -0600 commented question How to exclude outliers from detected Orb features?

@supra56 the code is working as expected, I simply want to add an additional step to remove points from the matches. I'v

2019-11-19 03:01:39 -0600 edited question How to exclude outliers from detected Orb features?

How to exclude outliers from detected Orb features? I am using the approach shown below (see bottom of post) to detect a

2019-11-19 02:42:24 -0600 commented answer How to exclude outliers from detected Orb features?

Thanks, but isn't this the purpose of dmatches = sorted(matches, key = lambda x:x.distance) ? I'm not looking for the cl

2019-11-18 12:56:55 -0600 edited question How to exclude outliers from detected Orb features?

How to exclude outliers from detected Orb features? I am using the approach shown below (see bottom of post) to detect a

2019-11-18 12:55:25 -0600 asked a question How to exclude outliers from detected Orb features?

How to exclude outliers from detected Orb features? I am using the approach shown below (see bottom of post) to detect a

2019-11-18 05:28:56 -0600 received badge  Enthusiast
2019-11-13 02:49:13 -0600 received badge  Supporter (source)
2019-11-12 11:51:53 -0600 edited question Identifying and tracking drinks bottles in OpenCV *without* machine learning

Identifying and tracking drinks bottles in OpenCV *without* machine learning Earlier this year Nick Bourdakos posted a s

2019-11-12 11:43:13 -0600 received badge  Editor (source)
2019-11-12 11:43:13 -0600 edited question Identifying and tracking drinks bottles in OpenCV *without* machine learning

Identifying drinks bottles *without* machine learning Earlier this year Nick Bourdakos posted a series of tweets demoing

2019-11-12 10:54:16 -0600 commented question Identifying and tracking drinks bottles in OpenCV *without* machine learning

Can you tell me please, how is this off-topic?

2019-11-12 10:26:28 -0600 asked a question Identifying and tracking drinks bottles in OpenCV *without* machine learning

Identifying drinks bottles *without* machine learning Earlier this year Nick Bourdakos posted a series of tweets demoing