修改了qt测试程序,但是im指令测试未通过
0
.gitignore
vendored
Normal file → Executable file
79
QT_test.py
Normal file → Executable file
@ -7,7 +7,7 @@ import logging
|
||||
import socket
|
||||
import numpy as np
|
||||
import cv2
|
||||
import binascii
|
||||
|
||||
|
||||
|
||||
def rec_socket(recv_sock: socket.socket, cmd_type: str, ack: bool) -> bool:
|
||||
@ -77,20 +77,21 @@ def rec_socket(recv_sock: socket.socket, cmd_type: str, ack: bool) -> bool:
|
||||
|
||||
def main():
|
||||
socket_receive = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
socket_receive.bind(('127.0.0.1', 23456))
|
||||
socket_receive.bind(('127.0.0.1', 21123))
|
||||
socket_receive.listen(5)
|
||||
# socket_send = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
# socket_send.bind(('127.0.0.1', 21122))
|
||||
# socket_send.listen(5)
|
||||
socket_send = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
socket_send.bind(('127.0.0.1', 21122))
|
||||
socket_send.listen(5)
|
||||
print('等待连接')
|
||||
socket_send_1, receive_addr_1 = socket_receive.accept()
|
||||
socket_send_1, receive_addr_1 = socket_send.accept()
|
||||
print("连接成功:", receive_addr_1)
|
||||
socket_send_2 = socket_send_1
|
||||
# socket_send_2, receive_addr_2 = socket_receive.accept()
|
||||
# print("连接成功:", receive_addr_2)
|
||||
# socket_send_2 = socket_send_1
|
||||
socket_send_2, receive_addr_2 = socket_receive.accept()
|
||||
print("连接成功:", receive_addr_2)
|
||||
while True:
|
||||
cmd = input().strip().upper()
|
||||
if cmd == 'IM':
|
||||
# img = cv2.imread(r"/Users/zhouchao/Library/CloudStorage/OneDrive-macrosolid/PycharmProjects/wood_color/data/data20220919/dark/rgb60.png")
|
||||
img = cv2.imread(r"C:\Users\FEIJINTI\PycharmProjects\wood_color\data\data20220919\dark\rgb60.png")
|
||||
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
||||
img = np.asarray(img, dtype=np.float32)
|
||||
@ -101,20 +102,21 @@ def main():
|
||||
length = length.to_bytes(4, byteorder='big')
|
||||
width = width.to_bytes(2, byteorder='big')
|
||||
height = height.to_bytes(2, byteorder='big')
|
||||
send_message = b'\xaa' + length + (' ' + cmd).upper().encode('ascii') + width + height
|
||||
send_message = b'\xaa' + length + (' ' + cmd).upper().encode('ascii') + width + height + img_bytes + b'\xff\xff\xbb'
|
||||
socket_send_1.send(send_message)
|
||||
socket_send_1.send(img_bytes)
|
||||
socket_send_1.send(b'\xff\xff\xbb')
|
||||
print('发送成功')
|
||||
if rec_socket(socket_send_2, cmd_type=cmd, ack=True):
|
||||
print('接收指令成功')
|
||||
else:
|
||||
print('接收指令失败')
|
||||
if rec_socket(socket_send_2, cmd_type=cmd, ack=False):
|
||||
print('指令执行完毕')
|
||||
else:
|
||||
print('指令执行失败')
|
||||
result = socket_send_2.recv(1)
|
||||
print(result)
|
||||
# if rec_socket(socket_send_2, cmd_type=cmd, ack=True):
|
||||
# print('接收指令成功')
|
||||
# else:
|
||||
# print('接收指令失败')
|
||||
# if rec_socket(socket_send_2, cmd_type=cmd, ack=False):
|
||||
# print('指令执行完毕')
|
||||
# else:
|
||||
# print('指令执行失败')
|
||||
elif cmd == 'TR':
|
||||
# model = "/Users/zhouchao/Library/CloudStorage/OneDrive-macrosolid/PycharmProjects/wood_color/data/data20220919"
|
||||
model = "C:/Users/FEIJINTI/PycharmProjects/wood_color/data/data20220919"
|
||||
model = model.encode('ascii')
|
||||
length = len(model) + 4
|
||||
@ -122,15 +124,18 @@ def main():
|
||||
send_message = b'\xaa' + length + (' ' + cmd).upper().encode('ascii') + model + b'\xff\xff\xbb'
|
||||
socket_send_1.send(send_message)
|
||||
print('发送成功')
|
||||
if rec_socket(socket_send_2, cmd_type=cmd, ack=True):
|
||||
print('接收指令成功')
|
||||
else:
|
||||
print('接收指令失败')
|
||||
if rec_socket(socket_send_2, cmd_type=cmd, ack=False):
|
||||
print('指令执行完毕')
|
||||
else:
|
||||
print('指令执行失败')
|
||||
result = socket_send_2.recv(1)
|
||||
print(result)
|
||||
# if rec_socket(socket_send_2, cmd_type=cmd, ack=True):
|
||||
# print('接收指令成功')
|
||||
# else:
|
||||
# print('接收指令失败')
|
||||
# if rec_socket(socket_send_2, cmd_type=cmd, ack=False):
|
||||
# print('指令执行完毕')
|
||||
# else:
|
||||
# print('指令执行失败')
|
||||
elif cmd == 'MD':
|
||||
# model = "/Users/zhouchao/Library/CloudStorage/OneDrive-macrosolid/PycharmProjects/wood_color/models/model_2020-11-08_20-49.p"
|
||||
model = "C:/Users/FEIJINTI/PycharmProjects/wood_color/models/model_2020-11-08_20-49.p"
|
||||
model = model.encode('ascii')
|
||||
length = len(model) + 4
|
||||
@ -138,14 +143,16 @@ def main():
|
||||
send_message = b'\xaa' + length + (' ' + cmd).upper().encode('ascii') + model + b'\xff\xff\xbb'
|
||||
socket_send_1.send(send_message)
|
||||
print('发送成功')
|
||||
if rec_socket(socket_send_2, cmd_type=cmd, ack=True):
|
||||
print('接收指令成功')
|
||||
else:
|
||||
print('接收指令失败')
|
||||
if rec_socket(socket_send_2, cmd_type=cmd, ack=False):
|
||||
print('指令执行完毕')
|
||||
else:
|
||||
print('指令执行失败')
|
||||
result = socket_send_2.recv(1)
|
||||
print(result)
|
||||
# if rec_socket(socket_send_2, cmd_type=cmd, ack=True):
|
||||
# print('接收指令成功')
|
||||
# else:
|
||||
# print('接收指令失败')
|
||||
# if rec_socket(socket_send_2, cmd_type=cmd, ack=False):
|
||||
# print('指令执行完毕')
|
||||
# else:
|
||||
# print('指令执行失败')
|
||||
else:
|
||||
print('指令错误')
|
||||
|
||||
|
||||
0
classifer.py
Normal file → Executable file
0
pics/TODO.png
Normal file → Executable file
|
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 30 KiB |
0
pics/result.png
Normal file → Executable file
|
Before Width: | Height: | Size: 34 KiB After Width: | Height: | Size: 34 KiB |
0
pics/从木板中提取色彩.png
Normal file → Executable file
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
0
pics/色彩分类.png
Normal file → Executable file
|
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 26 KiB |
1
root_dir.py
Normal file → Executable file
@ -8,3 +8,4 @@ Created on Nov 3 21:18:26 2020
|
||||
import os
|
||||
|
||||
ROOT_DIR = r"C:\Users\FEIJINTI\PycharmProjects\wood_color"
|
||||
# ROOT_DIR = r"/Users/zhouchao/Library/CloudStorage/OneDrive-macrosolid/PycharmProjects/wood_color"
|
||||
@ -52,6 +52,7 @@ def main(is_debug=False):
|
||||
|
||||
while not dual_sock.status:
|
||||
dual_sock.reconnect()
|
||||
# model_path = os.path.join(ROOT_DIR, r"/Users/zhouchao/Library/CloudStorage/OneDrive-macrosolid/PycharmProjects/wood_color/models/model_2022-09-28_13-15.p")
|
||||
model_path = os.path.join(ROOT_DIR, r"C:\Users\FEIJINTI\PycharmProjects\wood_color\models\model_2022-09-28_13-15.p")
|
||||
detector = WoodClass(w=4096, h=1200, n=3000, debug_mode=False)
|
||||
detector.load(path=model_path)
|
||||
|
||||
7
utils.py
Normal file → Executable file
@ -113,7 +113,7 @@ class PreSocket(socket.socket):
|
||||
|
||||
|
||||
class DualSock(PreSocket):
|
||||
def __init__(self, connect_ip='127.0.0.1', recv_port:int = 21122, send_port: int = 21123):
|
||||
def __init__(self, connect_ip='127.0.0.1', recv_port: int = 21122, send_port: int = 21123):
|
||||
super().__init__()
|
||||
received_status, self.received_sock = try_connect(connect_ip=connect_ip, port_number=recv_port)
|
||||
send_status, self.send_sock = try_connect(connect_ip=connect_ip, port_number=send_port)
|
||||
@ -125,8 +125,9 @@ class DualSock(PreSocket):
|
||||
def receive(self, *args, **kwargs) -> bytes:
|
||||
return self.received_sock.receive(*args, **kwargs)
|
||||
|
||||
def set_prepack(self, *args, **kwargs):
|
||||
return self.received_sock.receive(*args, **kwargs)
|
||||
# def set_prepack(self, pre_pack: bytes):
|
||||
# temp = self.pre_pack
|
||||
# self.pre_pack = temp + pre_pack
|
||||
|
||||
def reconnect(self, connect_ip='127.0.0.1', recv_port:int = 21122, send_port: int = 21123):
|
||||
received_status, self.received_sock = try_connect(connect_ip=connect_ip, port_number=recv_port)
|
||||
|
||||