openmv如何实现主程序调用热点让手机能看到实时画面,脱机状态下需要使用几块锂电池能同时为云台,摄像,WiFi供电?
-
主程序: import sensor, image, time,network,usocket,sys from pid import PID from pyb import Servo pan_servo=Servo(1) tilt_servo=Servo(2) red_threshold = (0, 12, -128, 1, -128, 16) pan_pid = PID(p=0.27, i=0, imax=90) tilt_pid = PID(p=0.25, i=0, imax=90) sensor.reset() # Initialize the camera sensor. sensor.set_pixformat(sensor.RGB565) # use RGB565. sensor.set_framesize(sensor.QQVGA) # use QQVGA for speed. sensor.skip_frames(10) # Let new settings take affect. sensor.set_auto_whitebal(False) # turn this off. clock = time.clock() # Tracks FPS. def find_max(blobs): max_size=0 for blob in blobs: if blob[2]*blob[2] > max_size: max_blob=blob max_size = blob[2]*blob[2] return max_blob while(True): clock.tick() # Track elapsed milliseconds between snapshots(). img = sensor.snapshot().lens_corr(1.8) # Take a picture and return the image.畸变校正 blobs = img.find_circles(threshold = 3500, x_margin = 10, y_margin = 10, r_margin = 10,r_min = 2, r_max = 100, r_step = 2)#为识别到圆的区域: if blobs: max_blob = find_max(blobs) pan_error = max_blob[0]-img.width()/2 tilt_error = max_blob[1]-img.height()/2 #色块的xy左标 print("pan_error: ", pan_error) img.draw_circle(max_blob.x(), max_blob.y(), max_blob.r(), color = (255, 0, 0))#画圆 img.draw_cross(int(max_blob[0]),int(max_blob[1])) # cx, cy#画十字 #PID计算 pan_output=pan_pid.get_pid(pan_error,1)/2 tilt_output=tilt_pid.get_pid(tilt_error,1) print("pan_output",pan_output) pan_servo.angle(pan_servo.angle()+pan_output) tilt_servo.angle(tilt_servo.angle()-tilt_output)
WIFI:
import sensor, image, time, network, usocket, sys
SSID ='OPENMV_AP'
KEY ='1234567890'
HOST = ''
PORT = 8080
sensor.reset()
sensor.set_contrast(1)
sensor.set_brightness(1)
sensor.set_saturation(1)
sensor.set_gainceiling(16)
sensor.set_framesize(sensor.QQVGA)
sensor.set_pixformat(sensor.RGB565)
wlan = network.WINC(mode=network.WINC.MODE_AP)
wlan.start_ap(SSID, key=KEY, security=wlan.WEP, channel=2)
def start_streaming(s):
print ('Waiting for connections..')
client, addr = s.accept()
client.settimeout(2.0)
print ('Connected to ' + addr[0] + ':' + str(addr[1]))
data = client.recv(1024)
client.send("HTTP/1.1 200 OK\r\n"
"Server: OpenMV\r\n"
"Content-Type: multipart/x-mixed-replace;boundary=openmv\r\n"
"Cache-Control: no-cache\r\n"
"Pragma: no-cache\r\n\r\n")
clock = time.clock()
while (True):
clock.tick()
frame = sensor.snapshot()
cframe = frame.compressed(quality=35)
header = "\r\n--openmv\r\n"
"Content-Type: image/jpeg\r\n"
"Content-Length:"+str(cframe.size())+"\r\n\r\n"
client.send(header)
client.send(cframe)
print(clock.fps())
while (True):
s = usocket.socket(usocket.AF_INET, usocket.SOCK_STREAM)
try:
s.bind([HOST, PORT])
s.listen(5)
s.settimeout(3)
start_streaming(s)
except OSError as e:
s.close()
print("socket error: ", e)救急 希望大佬指点
-
WiFi扩展板和云台引脚冲突的。
-
如果是耗电问题的话,一个锂电池就行。
-
@kidswong999 那怎样可以解决这一问题?还是说只能实现云台或者WIFI其中一个功能。
-
https://singtown.com/learn/49596/
这个是WiFi图传的教程。
-
@e6tr 可以用舵机扩展板连接云台的舵机,但是也比较麻烦,代码要改。
-
@kidswong999 有没有可以参考的代码或视频,萌新不是很懂。。麻烦了