修改了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 socket
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import cv2
|
import cv2
|
||||||
import binascii
|
|
||||||
|
|
||||||
|
|
||||||
def rec_socket(recv_sock: socket.socket, cmd_type: str, ack: bool) -> bool:
|
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():
|
def main():
|
||||||
socket_receive = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
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_receive.listen(5)
|
||||||
# socket_send = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
socket_send = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
# socket_send.bind(('127.0.0.1', 21122))
|
socket_send.bind(('127.0.0.1', 21122))
|
||||||
# socket_send.listen(5)
|
socket_send.listen(5)
|
||||||
print('等待连接')
|
print('等待连接')
|
||||||
socket_send_1, receive_addr_1 = socket_receive.accept()
|
socket_send_1, receive_addr_1 = socket_send.accept()
|
||||||
print("连接成功:", receive_addr_1)
|
print("连接成功:", receive_addr_1)
|
||||||
socket_send_2 = socket_send_1
|
# socket_send_2 = socket_send_1
|
||||||
# socket_send_2, receive_addr_2 = socket_receive.accept()
|
socket_send_2, receive_addr_2 = socket_receive.accept()
|
||||||
# print("连接成功:", receive_addr_2)
|
print("连接成功:", receive_addr_2)
|
||||||
while True:
|
while True:
|
||||||
cmd = input().strip().upper()
|
cmd = input().strip().upper()
|
||||||
if cmd == 'IM':
|
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.imread(r"C:\Users\FEIJINTI\PycharmProjects\wood_color\data\data20220919\dark\rgb60.png")
|
||||||
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
||||||
img = np.asarray(img, dtype=np.float32)
|
img = np.asarray(img, dtype=np.float32)
|
||||||
@ -101,20 +102,21 @@ def main():
|
|||||||
length = length.to_bytes(4, byteorder='big')
|
length = length.to_bytes(4, byteorder='big')
|
||||||
width = width.to_bytes(2, byteorder='big')
|
width = width.to_bytes(2, byteorder='big')
|
||||||
height = height.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(send_message)
|
||||||
socket_send_1.send(img_bytes)
|
|
||||||
socket_send_1.send(b'\xff\xff\xbb')
|
|
||||||
print('发送成功')
|
print('发送成功')
|
||||||
if rec_socket(socket_send_2, cmd_type=cmd, ack=True):
|
result = socket_send_2.recv(1)
|
||||||
print('接收指令成功')
|
print(result)
|
||||||
else:
|
# if rec_socket(socket_send_2, cmd_type=cmd, ack=True):
|
||||||
print('接收指令失败')
|
# print('接收指令成功')
|
||||||
if rec_socket(socket_send_2, cmd_type=cmd, ack=False):
|
# else:
|
||||||
print('指令执行完毕')
|
# print('接收指令失败')
|
||||||
else:
|
# if rec_socket(socket_send_2, cmd_type=cmd, ack=False):
|
||||||
print('指令执行失败')
|
# print('指令执行完毕')
|
||||||
|
# else:
|
||||||
|
# print('指令执行失败')
|
||||||
elif cmd == 'TR':
|
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 = "C:/Users/FEIJINTI/PycharmProjects/wood_color/data/data20220919"
|
||||||
model = model.encode('ascii')
|
model = model.encode('ascii')
|
||||||
length = len(model) + 4
|
length = len(model) + 4
|
||||||
@ -122,15 +124,18 @@ def main():
|
|||||||
send_message = b'\xaa' + length + (' ' + cmd).upper().encode('ascii') + model + b'\xff\xff\xbb'
|
send_message = b'\xaa' + length + (' ' + cmd).upper().encode('ascii') + model + b'\xff\xff\xbb'
|
||||||
socket_send_1.send(send_message)
|
socket_send_1.send(send_message)
|
||||||
print('发送成功')
|
print('发送成功')
|
||||||
if rec_socket(socket_send_2, cmd_type=cmd, ack=True):
|
result = socket_send_2.recv(1)
|
||||||
print('接收指令成功')
|
print(result)
|
||||||
else:
|
# if rec_socket(socket_send_2, cmd_type=cmd, ack=True):
|
||||||
print('接收指令失败')
|
# print('接收指令成功')
|
||||||
if rec_socket(socket_send_2, cmd_type=cmd, ack=False):
|
# else:
|
||||||
print('指令执行完毕')
|
# print('接收指令失败')
|
||||||
else:
|
# if rec_socket(socket_send_2, cmd_type=cmd, ack=False):
|
||||||
print('指令执行失败')
|
# print('指令执行完毕')
|
||||||
|
# else:
|
||||||
|
# print('指令执行失败')
|
||||||
elif cmd == 'MD':
|
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 = "C:/Users/FEIJINTI/PycharmProjects/wood_color/models/model_2020-11-08_20-49.p"
|
||||||
model = model.encode('ascii')
|
model = model.encode('ascii')
|
||||||
length = len(model) + 4
|
length = len(model) + 4
|
||||||
@ -138,14 +143,16 @@ def main():
|
|||||||
send_message = b'\xaa' + length + (' ' + cmd).upper().encode('ascii') + model + b'\xff\xff\xbb'
|
send_message = b'\xaa' + length + (' ' + cmd).upper().encode('ascii') + model + b'\xff\xff\xbb'
|
||||||
socket_send_1.send(send_message)
|
socket_send_1.send(send_message)
|
||||||
print('发送成功')
|
print('发送成功')
|
||||||
if rec_socket(socket_send_2, cmd_type=cmd, ack=True):
|
result = socket_send_2.recv(1)
|
||||||
print('接收指令成功')
|
print(result)
|
||||||
else:
|
# if rec_socket(socket_send_2, cmd_type=cmd, ack=True):
|
||||||
print('接收指令失败')
|
# print('接收指令成功')
|
||||||
if rec_socket(socket_send_2, cmd_type=cmd, ack=False):
|
# else:
|
||||||
print('指令执行完毕')
|
# print('接收指令失败')
|
||||||
else:
|
# if rec_socket(socket_send_2, cmd_type=cmd, ack=False):
|
||||||
print('指令执行失败')
|
# print('指令执行完毕')
|
||||||
|
# else:
|
||||||
|
# print('指令执行失败')
|
||||||
else:
|
else:
|
||||||
print('指令错误')
|
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 |
3
root_dir.py
Normal file → Executable file
@ -7,4 +7,5 @@ Created on Nov 3 21:18:26 2020
|
|||||||
"""
|
"""
|
||||||
import os
|
import os
|
||||||
|
|
||||||
ROOT_DIR = r"C:\Users\FEIJINTI\PycharmProjects\wood_color"
|
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:
|
while not dual_sock.status:
|
||||||
dual_sock.reconnect()
|
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")
|
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 = WoodClass(w=4096, h=1200, n=3000, debug_mode=False)
|
||||||
detector.load(path=model_path)
|
detector.load(path=model_path)
|
||||||
|
|||||||
7
utils.py
Normal file → Executable file
@ -113,7 +113,7 @@ class PreSocket(socket.socket):
|
|||||||
|
|
||||||
|
|
||||||
class DualSock(PreSocket):
|
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__()
|
super().__init__()
|
||||||
received_status, self.received_sock = try_connect(connect_ip=connect_ip, port_number=recv_port)
|
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)
|
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:
|
def receive(self, *args, **kwargs) -> bytes:
|
||||||
return self.received_sock.receive(*args, **kwargs)
|
return self.received_sock.receive(*args, **kwargs)
|
||||||
|
|
||||||
def set_prepack(self, *args, **kwargs):
|
# def set_prepack(self, pre_pack: bytes):
|
||||||
return self.received_sock.receive(*args, **kwargs)
|
# 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):
|
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)
|
received_status, self.received_sock = try_connect(connect_ip=connect_ip, port_number=recv_port)
|
||||||
|
|||||||