def picture(): with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: s.connect((IP_ADDRESS, PORT)) writer = s.makefile('wb') cap = cv2.VideoCapture(camera_pin) ret, image = cap.read() if not ret: print('실패-----------------------------') return image = to_jpg(image) net2.send(writer, image) cap.release() buzzer.beep(0.1, n=1)
def receiver(client, addr): global counter counter += 1 # 스레드 별로 imshow에서 사용할 타이틀을 다르게 하기 위해서 frame_name = f'frame{counter}' reader = client.makefile('rb') writer = client.makefile('wb') while True: data, data_len = net2.receive(reader) if not data: break # print('received ', data_len) # 이미지 처리 # AI 알고리즘 처리 - 불량 여부 판단... 여기에 넣으면됭 show_image(data, frame_name) result = json.dumps({'result': 'ok'}) net2.send(writer, result.encode()) print('exit receiver')
def vido_streaming(): with socket.socket() as s: s.connect((HOST,PORT)) writer = s.makefile('wb') reader = s.makefile('rb') stream=io.BytesIO() for _ in camera.capture_continuous(stream,'jpeg',use_video_port=True): image=stream.getvalue() net2.send(writer,image) result=net2.receive(reader)[0] stream.seek(0) stream.truncate() if not button.is_pressed: writer.write(struct.pack('<L',0)) writer.flush() break