|
|
|
@ -22,7 +22,7 @@ def rectFromPoint(center, len, width, axis):
|
|
|
|
|
return rect
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def rectsFromPoint(center, l1, l2, l3, w, axis):
|
|
|
|
|
def rectsFromPoint(center, l1, l2, l3, w, cOffset, axis):
|
|
|
|
|
centerFine = center
|
|
|
|
|
fineInner = rectFromPoint(centerFine, l1, w, axis)
|
|
|
|
|
if(axis == 'x'):
|
|
|
|
@ -36,25 +36,25 @@ def rectsFromPoint(center, l1, l2, l3, w, axis):
|
|
|
|
|
|
|
|
|
|
centerCoarse = center
|
|
|
|
|
if(axis == 'x'):
|
|
|
|
|
centerCoarse = (center[0], center[1] + w)
|
|
|
|
|
centerCoarse = (center[0], center[1] + cOffset)
|
|
|
|
|
elif(axis == 'y'):
|
|
|
|
|
centerCoarse = (center[0] + w, center[1])
|
|
|
|
|
centerCoarse = (center[0] + cOffset, center[1])
|
|
|
|
|
coarse = rectFromPoint(centerCoarse, l3, w, axis)
|
|
|
|
|
|
|
|
|
|
return [fineInnerNeg, fineInnerPos, fineInner, fineOuter, coarse, center]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def moveROI(event, x, y, flags, params):
|
|
|
|
|
global roiX, roiY, moving, l1, l2, l3, w, selectedAxis
|
|
|
|
|
global roiX, roiY, moving, l1, l2, l3, w, cOffset, selectedAxis
|
|
|
|
|
if event == cv2.EVENT_LBUTTONDOWN:
|
|
|
|
|
moving = True
|
|
|
|
|
|
|
|
|
|
elif event==cv2.EVENT_MOUSEMOVE:
|
|
|
|
|
if moving==True:
|
|
|
|
|
if(selectedAxis == 'x'):
|
|
|
|
|
roiX = rectsFromPoint((x, y), l1, l2, l3, w, selectedAxis)
|
|
|
|
|
roiX = rectsFromPoint((x, y), l1, l2, l3, w, cOffset, selectedAxis)
|
|
|
|
|
elif(selectedAxis == 'y'):
|
|
|
|
|
roiY = rectsFromPoint((x, y), l1, l2, l3, w, selectedAxis)
|
|
|
|
|
roiY = rectsFromPoint((x, y), l1, l2, l3, w, cOffset, selectedAxis)
|
|
|
|
|
|
|
|
|
|
elif event == cv2.EVENT_LBUTTONUP:
|
|
|
|
|
moving = False
|
|
|
|
@ -118,7 +118,7 @@ def drawRoi(frame, roi):
|
|
|
|
|
cv2.line(frame, (center[0], center[1] - 5), (center[0], center[1] + 5), (0, 255, 0), 1)
|
|
|
|
|
|
|
|
|
|
def picameraToCVTrack():
|
|
|
|
|
global roiX, roiY, moving, l1, l2, l3, w, selectedAxis, dilationKernel, calibrate, oscClient
|
|
|
|
|
global roiX, roiY, moving, l1, l2, l3, w, selectedAxis, dilationVal, dilationKernel, calibrate, oscClient
|
|
|
|
|
|
|
|
|
|
while True:
|
|
|
|
|
frame = picam2.capture_buffer("lores")
|
|
|
|
@ -148,14 +148,18 @@ def picameraToCVTrack():
|
|
|
|
|
if key == ord('+'):
|
|
|
|
|
dilationVal = dilationVal + 1
|
|
|
|
|
dilationKernel = genDKernel(dilationVal)
|
|
|
|
|
print(dilationVal)
|
|
|
|
|
elif key == ord('-'):
|
|
|
|
|
if dilationVal > 0:
|
|
|
|
|
dilationVal = dilationVal - 1
|
|
|
|
|
dilationKernel = genDKernel(dilationVal)
|
|
|
|
|
print(dilationVal)
|
|
|
|
|
elif key == ord('x'):
|
|
|
|
|
selectedAxis = 'x'
|
|
|
|
|
print(selectedAxis)
|
|
|
|
|
elif key == ord('y'):
|
|
|
|
|
selectedAxis = 'y'
|
|
|
|
|
print(selectedAxis)
|
|
|
|
|
elif key == ord('c'):
|
|
|
|
|
if calibrate:
|
|
|
|
|
calibrate = False
|
|
|
|
@ -220,12 +224,13 @@ moving = False
|
|
|
|
|
l1 = 100
|
|
|
|
|
l2 = 300
|
|
|
|
|
l3 = 40
|
|
|
|
|
w = 20
|
|
|
|
|
w = 10
|
|
|
|
|
cOffset = 23;
|
|
|
|
|
roiXCenter = (384, 20)
|
|
|
|
|
roiYCenter = (20, 384)
|
|
|
|
|
roiX = rectsFromPoint(roiXCenter, l1, l2, l3, w, 'x')
|
|
|
|
|
roiY = rectsFromPoint(roiYCenter, l1, l2, l3, w, 'y')
|
|
|
|
|
dilationVal = 75
|
|
|
|
|
roiX = rectsFromPoint(roiXCenter, l1, l2, l3, w, cOffset, 'x')
|
|
|
|
|
roiY = rectsFromPoint(roiYCenter, l1, l2, l3, w, cOffset, 'y')
|
|
|
|
|
dilationVal = 70
|
|
|
|
|
dilationKernel = genDKernel(dilationVal)
|
|
|
|
|
calibrate = True
|
|
|
|
|
|
|
|
|
|