#将brg图像转化为rgb图像,工具类中有封装
self._sock.sendto(IOUtil.array_to_bytes(frame[…,::-1]),address)
except Exception as e:
logger.error(“分发器错误:”+str(e))
def dispenseCommand(self,command,address):
if command is None:
return
try:
self._sock.sendto(bytes(command),address)
except Exception as e:
raise Exception(e)
def close(self):
self._sock.close()
2.主控程序编写,python的多线程模块无法优化CPU密集型任务,但在后期会用多进程对程序进行优化,所以目前使用类似的多线程模式
#encoding=utf-8
import cv2
from managers import CameraManager
from transmitters import Dispatcher
from threading import Thread
from settings import *
import time
import copy
import multiprocessing
from utils import IOUtil,logger
‘’’
主控程序
‘’’
class Camera(object):
#主控程序
def init(self,captureManager = None,dispatcher = None,isShow=True):
‘’’
:param captureManager: 视屏采集器
:param dispatcher:信息分发器
‘’’
logger.info(“主控程序初始化…”)
self.captureManager = captureManager if captureManager is not None else CameraManager(cv2.VideoCapture(0))
self.dispatcher = dispatcher if dispatcher is not None else Dispatcher()
#是否开启图像分发
self.isDispense = True
#是否在本地显示
self.isShow = isShow
#是否开启预警
self.isWarning = True
#item为预警器处理后的图像以及坐标信息
#原始图像
self.frame = None
logger.info(“主控程序初始化完毕…”)
def _dispatch(self):
#信息分发线程
logger.info(“是否开启图片分发:”+str(self.isDispense))
while self.isDispense:
try:
self.dispatcher.dispenseImage(self.frame,(IMAGE_IP,IMAGE_PORT))
except EOFError as e:
print(e)
def run(self):
logger.info(“\n################################################################”)
self.startDispatch()
self.captureManager.start()
time.sleep(1)
while self.captureManager.isWorking():
self.frame = self.captureManager.getFrame()
if self.frame is None:
continue
if self.isShow and self.frame is not None:
cv2.imshow(“show”,self.frame)
keycode = cv2.waitKey(1)
self.onKeypress(keycode)
def startDispatch(self):
#开启分发
logger.info(“开启分发”)
最后
四轮技术面+一轮hr面结束,学习到了不少,面试也是一个学习检测自己的过程,面试前大概复习了 一周的时间,把以前的代码看了一下,字节跳动比较注重算法,面试前刷了下leetcode和剑指offer, 也刷了些在牛客网上的面经。大概就说这些了,写代码去了~
祝大家都能收获大厂offer~
篇幅有限,仅展示部分内容