SET image='{fname}'
            WHERE num = '{num}'
            """
    try:
        cursor = db.cursor()
        cursor.execute(query)
        db.commit()
        cursor.close()

    except Exception as e:
        print(f'에러 : {e}')

    num += 1


def publish(topic, value):
    try:
        client.connect(IP_ADDRESS_PI)
        client.publish(topic, value)
        client.loop(2)
        # print(topic, value)
    except Exception as e:
        print(f"에러 {e}")


if __name__ == '__main__':
    t = threading.Thread(target=sub)
    t.start()
    net.server(IP_ADDRESS_PC, PORT, receiver)
    print('start server...')
예제 #2
0

def detect(frame):
    frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
    output_dict = api.inference_image(frame_rgb)
    output_dict = filtering(output_dict)
    return output_dict


def receiver(client, addr):
    reader = client.makefile('rb')
    writer = client.makefile('wb')
    while True:
        data, data_len = net.receive(reader)
        if not data:
            break
        # jpg decode
        data = np.frombuffer(data, dtype=np.uint8)
        data = cv2.imdecode(data, cv2.IMREAD_COLOR)

        outut_dict = detect(data)
        result = json.dumps(outut_dict, cls=NumpyEncoder)
        net.send(writer, result.encode())

    # 이미지 처리
    print('exit receiver')


print('start server...')
net.server(HOST, PORT, receiver)