改进了一下,
后面再考虑加上测距和陀螺仪模块
代码写得比较简单, 但效果做出来还可以。。。
配合着一个能跑python的win平板和一个热成像摄像头可以玩得不亦乐乎
不过就是电源的问题没解决, 解决了就可以户外了
用这段python代码就可以采集摄像头的数据了,我们接着要做的就是, 在上面画出十字和方框
Pythonimport cv2
import numpy as np
if __name__ == '__main__':
cap = cv2.VideoCapture(url)
while(True):
ret, frame = cap.read()
cv2.imshow('frame',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
画的过程不难, 但是毕竟麻烦
话不多说, 直接放出来吧
Pythonimport cv2
import numpy as np
if __name__ == '__main__':
img_count = 0
cap = cv2.VideoCapture('url')
w = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) # float `width`
h = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) # float `height`
CROSS_W = int(w / 8)
CROSS_H = int(h / 8)
RETICLE_W_SIZE = int(w / 7)
RETICLE_H_SIZE = int(w / 7)
DELTA = 40
SHIFT = 40
DASH = 80
while(True):
ret, frame = cap.read()
text_color = (255,0,0)
c1 = int(w/2)
c2 = int(h/2)
x1 = int(w/2 - CROSS_W/2)
y1 = int(h/2)
x11 = int(w/2 - CROSS_W/2 + DASH/2)
y11 = int(h/2)
x2 = int(w/2 + CROSS_W/2)
y2 = int(h/2)
x21 = int(w/2 + CROSS_W/2 - DASH/2)
y21 = int(h/2)
x3 = int(w/2)
y3 = int(h/2 - CROSS_H/2)
x31 = int(w/2)
y31 = int(h/2 - CROSS_H/2 + DASH/2)
x4 = int(w/2)
y4 = int(h/2 + CROSS_H/2)
x41 = int(w/2)
y41 = int(h/2 + CROSS_H/2 - DASH/2)
x5 = int(w/2 - RETICLE_W_SIZE/2 - SHIFT)
y5 = int(h/2 - RETICLE_H_SIZE/2)
x51 = int(w/2 - RETICLE_W_SIZE/2 - SHIFT)
y51 = int(h/2 - RETICLE_H_SIZE/2 + DELTA)
x52 = int(w/2 - RETICLE_W_SIZE/2 -SHIFT + DELTA)
y52 = int(h/2 - RETICLE_H_SIZE/2)
x6 = int(w/2 + RETICLE_W_SIZE/2 + SHIFT)
y6 = int(h/2 - RETICLE_H_SIZE/2)
x61 = int(w/2 + RETICLE_W_SIZE/2 + SHIFT)
y61 = int(h/2 - RETICLE_H_SIZE/2 + DELTA)
x62 = int(w/2 + RETICLE_W_SIZE/2 + SHIFT - DELTA)
y62 = int(h/2 - RETICLE_H_SIZE/2)
x7 = int(w/2 - RETICLE_W_SIZE/2 - SHIFT)
y7 = int(h/2 + RETICLE_H_SIZE/2)
x71 = int(w/2 - RETICLE_W_SIZE/2 - SHIFT)
y71 = int(h/2 + RETICLE_H_SIZE/2 - DELTA)
x72 = int(w/2 - RETICLE_W_SIZE/2 - SHIFT + DELTA)
y72 = int(h/2 + RETICLE_H_SIZE/2)
x8 = int(w/2 + RETICLE_W_SIZE/2 + SHIFT)
y8 = int(h/2 + RETICLE_H_SIZE/2)
x81 = int(w/2 + RETICLE_W_SIZE/2 - SHIFT + DELTA)
y81 = int(h/2 + RETICLE_H_SIZE/2)
x82 = int(w/2 + RETICLE_W_SIZE/2 + SHIFT)
y82 = int(h/2 + RETICLE_H_SIZE/2 - DELTA)
#cv2.line(frame,(x1,y1),(x2,y2),(255,255,255),1,cv2.LINE_AA)
#cv2.line(frame,(x3,y3),(x4,y4),(255,255,255),1,cv2.LINE_AA)
cv2.circle(frame, (c1,c2), radius=0, color=(255, 255, 255), thickness=-1)
cv2.line(frame,(x1,y1),(x11,y11),(255,255,255),1,cv2.LINE_AA)
cv2.line(frame,(x2,y2),(x21,y21),(255,255,255),1,cv2.LINE_AA)
cv2.line(frame,(x3,y3),(x31,y31),(255,255,255),1,cv2.LINE_AA)
cv2.line(frame,(x4,y4),(x41,y41),(255,255,255),1,cv2.LINE_AA)
cv2.line(frame,(x5,y5),(x51,y51),(255,255,255),1,cv2.LINE_AA)
cv2.line(frame,(x5,y5),(x52,y52),(255,255,255),1,cv2.LINE_AA)
cv2.line(frame,(x6,y6),(x61,y61),(255,255,255),1,cv2.LINE_AA)
cv2.line(frame,(x6,y6),(x62,y62),(255,255,255),1,cv2.LINE_AA)
cv2.line(frame,(x7,y7),(x71,y71),(255,255,255),1,cv2.LINE_AA)
cv2.line(frame,(x7,y7),(x72,y72),(255,255,255),1,cv2.LINE_AA)
cv2.line(frame,(x8,y8),(x81,y81),(255,255,255),1,cv2.LINE_AA)
cv2.line(frame,(x8,y8),(x82,y82),(255,255,255),1,cv2.LINE_AA)
cv2.putText(frame,'Thermal IR',(64,64),cv2.FONT_HERSHEY_COMPLEX,1,(255,255,255),1,cv2.LINE_AA)
cv2.imshow('frame',frame)
if cv2.waitKey(1) & 0xFF == ord('s'):
cv2.imwrite("frame%d.jpg" % img_count, frame)
img_count = img_count + 1
print("save one frame ok!")
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
如果你身边没有热成像摄像头, 用一般的摄像头也可以, 但是
Pythoncap = cv2.VideoCapture(url)
这一行要换成自己的摄像头地址
[修改于 1年5个月前 - 2023/08/06 10:03:48]
200字以内,仅用于支线交流,主线讨论请采用回复功能。