版本暂存
This commit is contained in:
14
test/test_capture.py
Normal file
14
test/test_capture.py
Normal file
@@ -0,0 +1,14 @@
|
||||
import cv2
|
||||
|
||||
|
||||
cap = cv2.VideoCapture(20)
|
||||
cap.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter.fourcc('M','J','P','G'))
|
||||
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 960)
|
||||
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 540)
|
||||
|
||||
while True:
|
||||
ret, frame = cap.read()
|
||||
if ret:
|
||||
cv2.imshow("frame",frame)
|
||||
cv2.waitKey(1)
|
||||
cv2.destroyAllWindows()
|
||||
@@ -1,18 +1,14 @@
|
||||
|
||||
import sys
|
||||
import os
|
||||
import sys
|
||||
parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
sys.path.append(parent_dir)
|
||||
|
||||
from utils import label_filter
|
||||
from loguru import logger
|
||||
from utils import tlabel
|
||||
import zmq
|
||||
import time
|
||||
from by_cmd_py import by_cmd_py
|
||||
import time
|
||||
from utils import CountRecord
|
||||
by_cmd = by_cmd_py()
|
||||
|
||||
|
||||
|
||||
context = zmq.Context()
|
||||
socket = context.socket(zmq.REQ)
|
||||
@@ -22,209 +18,22 @@ logger.info("subtask yolo client init")
|
||||
filter = label_filter(socket)
|
||||
filter.switch_camera(1)
|
||||
|
||||
def car_stop():
|
||||
for _ in range(3):
|
||||
by_cmd.send_speed_x(0)
|
||||
time.sleep(0.2)
|
||||
by_cmd.send_speed_omega(0)
|
||||
# 蓝色球使用
|
||||
def calibrate_right_new(label, offset, run = True, run_speed = 3.5):
|
||||
not_found_counts = 0
|
||||
ret, error = filter.aim_right(label)
|
||||
while not ret:
|
||||
not_found_counts += 1
|
||||
if not_found_counts >= 20:
|
||||
not_found_counts = 0
|
||||
error = -320 # error > 0 front run
|
||||
logger.info("calibrate_right_new:找不到次数超过 20 帧 直接前进寻找")
|
||||
break
|
||||
ret, error = filter.aim_right(label)
|
||||
|
||||
error += offset
|
||||
if abs(error) > 10 and run:
|
||||
if error > 0:
|
||||
by_cmd.send_speed_x(-run_speed)
|
||||
else:
|
||||
by_cmd.send_speed_x(run_speed)
|
||||
pass
|
||||
# 停的位置已经很接近目标,可以直接使用 distance 校准
|
||||
else:
|
||||
# logger.info("停车时误差就小于")
|
||||
# error = error * 3
|
||||
# if error > 0:
|
||||
# by_cmd.send_distance_x(-10, int(error))
|
||||
# else:
|
||||
# by_cmd.send_distance_x(10, int(-error))
|
||||
return
|
||||
while True:
|
||||
ret, error = filter.aim_right(label)
|
||||
while not ret:
|
||||
ret, error = filter.aim_right(label)
|
||||
error += offset
|
||||
if ret:
|
||||
if abs(error) <= 8:
|
||||
car_stop()
|
||||
logger.info("calibrate_right_new:行进时 误差小于 8 直接停车")
|
||||
|
||||
ret, error = filter.aim_right(label)
|
||||
while not ret:
|
||||
ret, error = filter.aim_right(label)
|
||||
error += offset
|
||||
logger.info(f"calibrate_right_new:停车后的误差是{error}")
|
||||
if abs(error) > 8:
|
||||
logger.info(f"calibrate_right_new:停车后的误差大于 8 使用 distance 校准")
|
||||
error = error * 3
|
||||
if error > 0:
|
||||
by_cmd.send_distance_x(-10, int(error))
|
||||
else:
|
||||
by_cmd.send_distance_x(10, int(-error))
|
||||
|
||||
break
|
||||
'''
|
||||
description: 校准新方法 找到后停止 然后根据 error 判断前后低速前进 error < 5 后直接停车
|
||||
如果停车后 error > 8 则使用 distance 校准
|
||||
这个方法仅用于在视野里能找到的情况下进行校准,并不能实现边走边寻找 然后再校准
|
||||
param {*} label
|
||||
param {*} offset
|
||||
param {*} run
|
||||
param {*} run_speed
|
||||
return {*}
|
||||
'''
|
||||
def calibrate_new(label, offset, run = True, run_speed = 3.5):
|
||||
not_found_counts = 0
|
||||
ret, box = filter.get(label)
|
||||
while not ret:
|
||||
not_found_counts += 1
|
||||
if not_found_counts >= 20:
|
||||
not_found_counts = 0
|
||||
error = -320 # error > 0 front run
|
||||
logger.info("calibrate_new:找不到次数超过 20 帧 直接前进寻找")
|
||||
ret, box = filter.get(label)
|
||||
|
||||
error = (box[0][2] + box[0][0] - 320) / 2 + offset
|
||||
if abs(error) > 10 and run:
|
||||
if error > 0:
|
||||
by_cmd.send_speed_x(-run_speed)
|
||||
else:
|
||||
by_cmd.send_speed_x(run_speed)
|
||||
# 停的位置已经很接近目标,可以直接使用 distance 校准
|
||||
else:
|
||||
if abs(error) > 8:
|
||||
logger.info(f"calibrate_new:停车后误差{error}大于 8 使用 distance 校准")
|
||||
# error = error # 3
|
||||
if error > 0:
|
||||
by_cmd.send_distance_x(-10, int(error))
|
||||
else:
|
||||
by_cmd.send_distance_x(10, int(-error))
|
||||
return
|
||||
logger.info(f"calibrate_new:停车后误差{error}小于 8 不校准")
|
||||
return
|
||||
while True:
|
||||
ret, box = filter.get(label)
|
||||
while not ret:
|
||||
ret, box = filter.get(label)
|
||||
|
||||
error = (box[0][2] + box[0][0] - 320) / 2 + offset
|
||||
if ret:
|
||||
if abs(error) <= 10: # 5
|
||||
car_stop()
|
||||
logger.info("calibrate_new:行进时 误差小于 10 直接停车")
|
||||
|
||||
ret, box = filter.get(label)
|
||||
while not ret:
|
||||
ret, box = filter.get(label)
|
||||
|
||||
error = (box[0][2] + box[0][0] - 320) / 2 + offset
|
||||
logger.info(f"calibrate_new:停车后的误差是{error}")
|
||||
if abs(error) > 8:
|
||||
logger.info(f"calibrate_new:停车后的误差大于 8 使用 distance 校准")
|
||||
error = error * 3
|
||||
logger.error(f"error * 3{error}")
|
||||
if error > 0:
|
||||
by_cmd.send_distance_x(-10, int(error))
|
||||
else:
|
||||
by_cmd.send_distance_x(10, int(-error))
|
||||
|
||||
break
|
||||
def explore_calibrate_new(label, offset, run_direc ,run_speed = 3.5):
|
||||
# run_direc == 1 向前
|
||||
if run_direc == 1:
|
||||
by_cmd.send_speed_x(run_speed)
|
||||
else:
|
||||
by_cmd.send_speed_x(-run_speed)
|
||||
|
||||
while True:
|
||||
ret, box = filter.get(label)
|
||||
while not ret:
|
||||
ret, box = filter.get(label)
|
||||
error = (box[0][2] + box[0][0] - 320) / 2 + offset
|
||||
if ret:
|
||||
logger.info(f"当前误差:{error}, box[{box[0][2]},{box[0][0]}]")
|
||||
# 校准速度越大 停车的条件越宽泛
|
||||
if abs(error) <= 20:
|
||||
car_stop()
|
||||
logger.info("explore_calibrate_new:行进时 误差小于 10 直接停车")
|
||||
|
||||
error_sum = 0
|
||||
for _ in range(3):
|
||||
ret, box = filter.get(label)
|
||||
while not ret:
|
||||
ret, box = filter.get(label)
|
||||
error = (box[0][2] + box[0][0] - 320) / 2 + offset
|
||||
error_sum += error
|
||||
error_sum /= 3
|
||||
# logger.info(f"停车后像素误差:{error}")
|
||||
logger.info(f"停车后像素误差:{error_sum}")
|
||||
# if abs(error) > 8:
|
||||
logger.info(f"explore_calibrate_new:停车后的误差大于 8 使用 distance 校准")
|
||||
error_sum = error_sum * 3
|
||||
logger.error(f"error * 3 {error}")
|
||||
if error > 0:
|
||||
by_cmd.send_distance_x(-10, int(error))
|
||||
else:
|
||||
by_cmd.send_distance_x(10, int(-error))
|
||||
|
||||
break
|
||||
|
||||
offset = 10
|
||||
# by_cmd.send_angle_claw_arm(217)
|
||||
# while True:
|
||||
# pass
|
||||
# while (by_cmd.send_angle_camera(180) == -1):
|
||||
# by_cmd.send_angle_camera(180)
|
||||
while (by_cmd.send_angle_camera(180) == -1):
|
||||
by_cmd.send_angle_camera(180)
|
||||
# by_cmd.send_speed_x(15)
|
||||
|
||||
find_counts = 0
|
||||
label = tlabel.HOSPITAL
|
||||
record = CountRecord(5)
|
||||
offset = 22
|
||||
label = [tlabel.LPILLER, tlabel.MPILLER, tlabel.SPILLER]
|
||||
while True:
|
||||
time.sleep(0.2)
|
||||
|
||||
|
||||
# ret = filter.find(label)
|
||||
# ret = filter.find(label)
|
||||
# if ret > 0:
|
||||
# find_counts += 1
|
||||
# if record(label):
|
||||
# car_stop()
|
||||
# if find_counts >= 5:
|
||||
# car_stop()
|
||||
ret, box = filter.get(label)
|
||||
while not ret:
|
||||
ret, box = filter.get(label)
|
||||
width = box[0][2] - box[0][0]
|
||||
logger.info(width)
|
||||
# error = (box[0][2] + box[0][0] - 320) / 2 + offset
|
||||
# explore_calibrate_new(tlabel.LPILLER, offset = 10, run_direc = 1, run_speed = 5)
|
||||
# calibrate_new(label, offset = 15, run = True)
|
||||
# car_stop()
|
||||
# time.sleep(0.5)
|
||||
# for _ in range(3):
|
||||
# calibrate_right_new(tlabel.BBALL, offset = 27, run = True, run_speed = 4)
|
||||
# logger.info("抓蓝色球")
|
||||
# time.sleep(5)
|
||||
# logger.info("抓取块")
|
||||
# time.sleep(0.1)
|
||||
ret, box = filter.get(tlabel.TPLATFORM)
|
||||
if ret:
|
||||
error = (box[0][2] + box[0][0] - 320) / 2 + offset
|
||||
logger.error(error)
|
||||
|
||||
# label = tlabel.HOSPITAL
|
||||
# ret, box = filter.get(label)
|
||||
# while not ret:
|
||||
# ret, box = filter.get(label)
|
||||
# width = box[0][2] - box[0][0]
|
||||
# logger.info(width)
|
||||
|
||||
|
||||
|
||||
32
test/test_ocr.py
Normal file
32
test/test_ocr.py
Normal file
@@ -0,0 +1,32 @@
|
||||
import zmq
|
||||
|
||||
|
||||
context = zmq.Context()
|
||||
socket = context.socket(zmq.REQ)
|
||||
socket.connect("tcp://localhost:6668")
|
||||
|
||||
filter_w = (213, 540)
|
||||
filter_h = (120, 360)
|
||||
|
||||
|
||||
while True:
|
||||
a = input("")
|
||||
socket.send_string("")
|
||||
resp = socket.recv_pyobj()
|
||||
print(resp)
|
||||
if resp.get('code') == 0:
|
||||
text = ''
|
||||
for item in resp.get('content'):
|
||||
if item['probability']['average'] < 0.90:
|
||||
continue
|
||||
box = item['location']
|
||||
center_x = box['left'] + box['width'] / 2
|
||||
center_y = box['top'] + box['height'] / 2
|
||||
if center_x < filter_w[0] or center_x > filter_w[1] \
|
||||
or center_y < filter_h[0] or center_y > filter_h[1]:
|
||||
continue
|
||||
text += item['words']
|
||||
print(text)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user