- more FPS by median blur on ROI only
git-svn-id: http://moon:8086/svn/software/trunk/projects/opencv@336 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
+28
-6
@@ -65,16 +65,27 @@ class MyRgbProcess(RgbProcess):
|
||||
gray = cv2.cvtColor(data,cv2.COLOR_BGR2GRAY)
|
||||
|
||||
img1_objects = data.copy()
|
||||
# Min / max approach
|
||||
gray_blurred = cv2.medianBlur(gray,3)
|
||||
minVal, maxVal, minLoc, maxLoc = cv2.minMaxLoc(gray_blurred)
|
||||
# Min / max on whole image
|
||||
minVal, maxVal, minLoc, maxLoc = cv2.minMaxLoc(gray)
|
||||
x = maxLoc[0]
|
||||
y = maxLoc[1]
|
||||
# get ROI with size roi_size centered at maxLoc
|
||||
roi_size = 21
|
||||
roi = self.getROI(gray, x, y, roi_size, roi_size)
|
||||
# do the blur on ROI
|
||||
roi_blurred = cv2.medianBlur(roi,5)
|
||||
# Re-calculate centers on blurred image
|
||||
minVal, maxVal, minLoc, maxLoc = cv2.minMaxLoc(roi_blurred)
|
||||
# adjust centers of unfiltered image (x, y are in global pixel space)
|
||||
x += maxLoc[0] - int((roi_size-1)/2)
|
||||
y += maxLoc[1] - int((roi_size-1)/2)
|
||||
|
||||
# Calculated dot fall-of over different windows
|
||||
rect = None
|
||||
state = 0
|
||||
ref_color = 1
|
||||
for roi_size in range(1,15):
|
||||
roi = gray[y-roi_size:y+roi_size, x-roi_size:x+roi_size]
|
||||
for roi_size in range(3,33,2):
|
||||
roi = self.getROI(gray, x, y, roi_size, roi_size)
|
||||
mean_color = cv2.mean(roi)
|
||||
if state == 0:
|
||||
ref_color = mean_color[0]
|
||||
@@ -86,7 +97,8 @@ class MyRgbProcess(RgbProcess):
|
||||
if km < 0.7:
|
||||
rect = [(x-roi_size, y-roi_size),(x+roi_size, y+roi_size)]
|
||||
break
|
||||
|
||||
|
||||
# Is object found?
|
||||
if rect is not None:
|
||||
if not self.isVisible:
|
||||
print ("Visible")
|
||||
@@ -101,6 +113,7 @@ class MyRgbProcess(RgbProcess):
|
||||
self.sendBrick(0, 0)
|
||||
self.isVisible = False
|
||||
|
||||
# Update preview
|
||||
showFrame = False
|
||||
if self.frameSkipCounter > 0:
|
||||
self.frameSkipCounter -= 1
|
||||
@@ -122,6 +135,15 @@ class MyRgbProcess(RgbProcess):
|
||||
data = struct.pack("f", errorY)
|
||||
ev3.system_command.write_mailbox(self.brick, 'ErrorY', data)
|
||||
|
||||
def getROI(self, img, x, y, w, h):
|
||||
w2 = int((w-1)/2)
|
||||
h2 = int((h-1)/2)
|
||||
xmin = max(0, x-w2)
|
||||
ymin = max(0, y-h2)
|
||||
xmax = min(self.res[0]-1, x+w2)
|
||||
ymax = min(self.res[1]-1, y+h2)
|
||||
return img[ymin:ymax, xmin:xmax]
|
||||
|
||||
if with_ev3:
|
||||
# Connect to brick
|
||||
with ev3.EV3() as brick:
|
||||
|
||||
Reference in New Issue
Block a user