从python脚本发送实时视频帧以启动Spring

问题描述

我有一个项目,其中包含脚本python,使用Spring Boot和vue.js作为前端的Web应用程序 所以我需要在服务器中运行脚本并提取车号牌,然后使用rest api发送它,这很好用,现在脚本将车牌本地化在框架中,然后将其发送到spring boot我使用了rest api post,但我不知道是否有效 this is my schema 脚本代码:

cap = cv2.VideoCapture(1)
counter=0
while(cap.isOpened()):
    ret,frame = cap.read()
    h,w,l = frame.shape
    frame = imutils.rotate(frame,270)
    if counter%6 == 0:
        licensePlate = []
        try:
            height,width = frame.shape[:2]
            frame = frame[:,:,0:3]
            (boxes,scores,classes) = lp_detector.detect(frame)
            vl_boxes = boxes[np.argwhere(scores>0.3).reshape(-1)]
            vl_scores = scores[np.argwhere(scores>0.3).reshape(-1)]
            if len(vl_boxes) > 0:
                for i in range(len(vl_boxes)):
                    box = vl_boxes[i]
                    cropped_vl = frame[box[0]:box[2],box[1]:box[3],:]
                    cv2.rectangle(frame,(box[1],box[0]),(box[3],box[2]),(0,255,0),2)
                    plate = frame[box[0]:box[2],box[1]:box[3]]
                    cv2.imshow('plate',plate)
                    licensePlate.append(opencvReadPlate(plate))
                    print("OpenCV+CNN : " + licensePlate[0])
                    payload = {'plate': licensePlate[0]}
                    requests.post('http://localhost:8082/plate',params=payload)
                    print("url : " + requests.url)
           else:
              print('Unable to align')
      except:
         pass
    counter+=1
    cv2.imshow('Video',frame)
    //from here I want to send the frames
    frame_im = cv2.cvtColor(frame,cv2.COLOR_BGR2RGB)
    pil_im = Image.fromarray(frame_im)
    stream = io.BytesIO()
    pil_im.save(stream,format="JPEG")
    stream.seek(0)
    img_for_post = stream.read()    
    files = {'image': img_for_post}
    requests.post(url='http://localhost:8082/video',files=files)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()
cv2.waitKey(0)
cv2.destroyAllWindows()

我的spring boot控制器:

@Controller
public class HttpStreamProxyController {
    @PostMapping("/video")
    public void getVidoeStream1() throws IOException {
        //what have I do here ?
    }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...