- 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:
+27
-5
@@ -65,16 +65,27 @@ class MyRgbProcess(RgbProcess):
|
|||||||
gray = cv2.cvtColor(data,cv2.COLOR_BGR2GRAY)
|
gray = cv2.cvtColor(data,cv2.COLOR_BGR2GRAY)
|
||||||
|
|
||||||
img1_objects = data.copy()
|
img1_objects = data.copy()
|
||||||
# Min / max approach
|
# Min / max on whole image
|
||||||
gray_blurred = cv2.medianBlur(gray,3)
|
minVal, maxVal, minLoc, maxLoc = cv2.minMaxLoc(gray)
|
||||||
minVal, maxVal, minLoc, maxLoc = cv2.minMaxLoc(gray_blurred)
|
|
||||||
x = maxLoc[0]
|
x = maxLoc[0]
|
||||||
y = maxLoc[1]
|
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
|
rect = None
|
||||||
state = 0
|
state = 0
|
||||||
ref_color = 1
|
ref_color = 1
|
||||||
for roi_size in range(1,15):
|
for roi_size in range(3,33,2):
|
||||||
roi = gray[y-roi_size:y+roi_size, x-roi_size:x+roi_size]
|
roi = self.getROI(gray, x, y, roi_size, roi_size)
|
||||||
mean_color = cv2.mean(roi)
|
mean_color = cv2.mean(roi)
|
||||||
if state == 0:
|
if state == 0:
|
||||||
ref_color = mean_color[0]
|
ref_color = mean_color[0]
|
||||||
@@ -87,6 +98,7 @@ class MyRgbProcess(RgbProcess):
|
|||||||
rect = [(x-roi_size, y-roi_size),(x+roi_size, y+roi_size)]
|
rect = [(x-roi_size, y-roi_size),(x+roi_size, y+roi_size)]
|
||||||
break
|
break
|
||||||
|
|
||||||
|
# Is object found?
|
||||||
if rect is not None:
|
if rect is not None:
|
||||||
if not self.isVisible:
|
if not self.isVisible:
|
||||||
print ("Visible")
|
print ("Visible")
|
||||||
@@ -101,6 +113,7 @@ class MyRgbProcess(RgbProcess):
|
|||||||
self.sendBrick(0, 0)
|
self.sendBrick(0, 0)
|
||||||
self.isVisible = False
|
self.isVisible = False
|
||||||
|
|
||||||
|
# Update preview
|
||||||
showFrame = False
|
showFrame = False
|
||||||
if self.frameSkipCounter > 0:
|
if self.frameSkipCounter > 0:
|
||||||
self.frameSkipCounter -= 1
|
self.frameSkipCounter -= 1
|
||||||
@@ -122,6 +135,15 @@ class MyRgbProcess(RgbProcess):
|
|||||||
data = struct.pack("f", errorY)
|
data = struct.pack("f", errorY)
|
||||||
ev3.system_command.write_mailbox(self.brick, 'ErrorY', data)
|
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:
|
if with_ev3:
|
||||||
# Connect to brick
|
# Connect to brick
|
||||||
with ev3.EV3() as brick:
|
with ev3.EV3() as brick:
|
||||||
|
|||||||
Reference in New Issue
Block a user