-
Notifications
You must be signed in to change notification settings - Fork 0
/
findPen.py
38 lines (30 loc) · 1.12 KB
/
findPen.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from toolbox.opencvFramework import *
from toolbox.setting import saveMotionini
#mode 1:Color
def runFindPen(mode:int):
camS=CamerSystem()
while True:
frame=None
if mode==1:
ori,frame=camS.ColorThreshold(keepOrigin=True,showSource=False)
elif mode==2:
ori, frame = camS.MotionThreshold(keepOrigin=True)
if frame is None:
break
(x, y, w, h) =camS.GetCenterByLongestContour(img=frame,type=ProcessType.Bound)
#MotionMethodTest
###
cv2.rectangle(ori, (x, y), (x + w, y + h), (0,0,255), 2)
X, Y = round((2 * x + w) / 2), round((2 * y + h) / 2)
#绘制中心十字线
centerRreference=(320,240)
cv2.line(ori, (320, 220), (320, 260), (0, 0, 255), 2)
cv2.line(ori, (300, 240), (340, 240), (0, 0, 255), 2)
# cv2.line(ori, (X,Y+20), (X,Y-20), (0, 0, 255), 2)
# cv2.line(ori, (X+20,Y), (X-20,Y), (0, 0, 255), 2)
cv2.imshow("Target", ori)
k = cv2.waitKey(int(1000 / camS.getFPS()))
if k == 27:
break
camS.releasCam()
cv2.destroyAllWindows()