当前位置:网站首页>Introduction to easydl object detection port
Introduction to easydl object detection port
2022-06-13 02:07:00 【weixin_ forty-four million five hundred and seventy-six thousan】
#A7
# -*- coding: utf-8 -*-
import requests
import os
import sys
from PIL import Image
import io
import cv2 as cv
import time
import socket
import traceback
import numpy as np
port = 24401 #sys.argv[1]
def img_tobyte(roi):
ret,buf=cv.imencode('.jpg',roi)
img_bin=Image.fromarray(np.uint8(buf)).tobytes()
return img_bin
def detect(imageName,flags=0):
item = imageName
factor = 1
th = 0.6
# img = open(item, 'rb').read()
src = cv.imread(item)
[height, width, c] = src.shape
#img_resize1 = cv.resize(src, (int(width*factor), int(height*factor)), interpolation=cv.INTER_CUBIC)
if flags=='0': # Crosswise
img_crop=src[580:1250,0:2048]
else:
img_crop=src[200:1536,0:2048]
img = img_tobyte(img_crop)
#cv.imwrite("cc11cc.jpg",img_crop)
num = 0
try:
result = requests.post("http://127.0.0.1:{}/".format(port),params={'threshold': 0.3}, data=img, timeout=(0.01, 0.4)).json()
res = result['results']
for i in res:
if i['confidence'] > th and i['label']=='1':
num = num+1
except:
num = -1
return num
imageName='test_img/0-1627999873415.jpg'
num=detect(imageName,flags=0)
print(num)
# Input : Picture path Output is : Number of tests
# function : testing
import requests
import os
import sys
from PIL import Image
import io
import cv2 as cv
import time
import socket
import traceback
import numpy as np
port = 24401 #sys.argv[1]
def img_tobyte(roi):
ret,buf=cv.imencode('.jpg',roi)
img_bin=Image.fromarray(np.uint8(buf)).tobytes()
return img_bin
def detect(imageName,flag=0):
item = imageName
factor = 1
th = 0.2
src = cv.imread(item)
[height, width, c] = src.shape
if int(flag)==1:
img_crop=src[0:844,0:2048]
else:
img_crop=src[200:1536,0:2048]
img = img_tobyte(img_crop)
num = 0
try:
result = requests.post("http://127.0.0.1:{}/".format(port),params={'threshold': 0.3}, data=img).json()
res = result['results']
for i in res:
if i['confidence'] > th and i['label']=='1':
num = num+1
except:
num = -1
return num
client_send = socket.socket()
ip_port = ("127.0.0.1", 8888)
def sendCommand(cmd): # TCP signal communication
global client_send
for i in range(5000):
try:
client_send.sendall(bytes(cmd, encoding="utf-8"))
data = client_send.recv(1024)
#client_send.close
except Exception as e:
print('str(Exception):\t', str(Exception))
print('str(e):\t\t', str(e))
print('repr(e):\t', repr(e))
# Get information about the exception that is currently being handled
exc_type, exc_value, exc_traceback = sys.exc_info()
print('e.message:\t', exc_value)
print("Note, object e and exc of Class %s is %s the same." %
(type(exc_value), ('not', '')[exc_value is e]))
print('traceback.print_exc(): ', traceback.print_exc())
print('traceback.format_exc():\n%s' % traceback.format_exc())
time.sleep(0.1)
client_send = socket.socket()
client_send.connect(ip_port)
print(' dispatch orders [{}] Failed to connect with the main program , frequency :{}'.format(cmd, i+1))
if(i >= 500):
print(' sign out ')
sys.exit()
#continue
else:
break
return str(data, encoding="utf-8").split("\n", 1)[0]
def sysPrint(txt): # Clear screen output
#os.system("cls")
print(txt)
if __name__ == "__main__":
debug = False # Local debugging mode The official deployment is changed to False
#debug = True
if(debug):
for i in range(1):
timeStart = time.time()
task = "1.jpg"
print("detect result:")
print(detect(task))
print(" testing :{} when :{} millisecond \n".format(
task, round((time.time()-timeStart)*1000)))
sys.exit()
client_send.connect(ip_port)
print("wait to detect...")
while(True):
task = sendCommand("task|")
if(task == ""):
time.sleep(0.1)
continue
taskArr=task.split('|')
task=taskArr[0]
flag=taskArr[1]
timeStart = time.time()
cmd = detect("z:/{}.jpg".format(task),flag)
cmd = "detect|{}|{}".format(task, cmd)
sendCommand(cmd)
sysPrint(" testing :{}.jpg when :{} millisecond ".format(
task, round((time.time()-timeStart)*1000)))
{'confidence': 0.9824954271316528,
'frame': 0, 'index': 2, 'label': '1',
# Top left coordinates , Object frame width and height
'location': {'height': 344, 'left': 164, 'top': 1043, 'width': 915},
'name': '1',
'score': 0.9824954271316528,
'trackId': 0,
'x1': 0.08011282980442047,
'x2': 0.5272660851478577,
'y1': 0.6792315244674683,
'y2': 0.9037220478057861},边栏推荐
- Record: how to solve the problem of "the system cannot find the specified path" in the picture message uploaded by transferto() of multipartfile class [valid through personal test]
- 如何解决通过new Date()获取时间写出数据库与当前时间相差8小时问题【亲测有效】
- STM32 IIC protocol controls pca9685 steering gear drive board
- Installing Oracle with docker for Mac
- 10 days based on stm32f401ret6 smart lock project practice day 1 (environment construction and new construction)
- C language conditional compilation routine
- Implementation of pointer linked list
- Uniapp preview function
- Qt实现思维导图功能(二)
- How many smart bids does Google have?
猜你喜欢

Uniapp preview function

1、 Set up Django automation platform (realize one click SQL execution)

Looking at Qianxin's "wild prospect" of network security from the 2021 annual performance report

What is the path field—— Competitive advertising
![How to solve the problem of obtaining the time through new date() and writing out the difference of 8 hours between the database and the current time [valid through personal test]](/img/c5/f17333cdb72a1ce09aa54e38dd0a8c.png)
How to solve the problem of obtaining the time through new date() and writing out the difference of 8 hours between the database and the current time [valid through personal test]

Vscode configuration header file -- Take opencv and its own header file as an example

(no plug-in) summary of vim basic shortcut keys
![[the third day of actual combat of smart lock project based on stm32f401ret6 in 10 days] communication foundation and understanding serial port](/img/82/ed215078da0325b3adf95dcd6ffe30.jpg)
[the third day of actual combat of smart lock project based on stm32f401ret6 in 10 days] communication foundation and understanding serial port

回顾ITIL各版本历程,找到企业运维发展的关键点
![[the second day of actual combat of smart lock project based on stm32f401ret6 in 10 days] GPIO and register](/img/eb/9bd411be74937371de0bbf3f04267e.jpg)
[the second day of actual combat of smart lock project based on stm32f401ret6 in 10 days] GPIO and register
随机推荐
What did Hello travel do right for 500million users in five years?
[open source] libinimini: a minimalist ini parsing library for single chip computers
rsync 傳輸排除目錄
Decoding iFLYTEK open platform 2.0 is a fertile land for developers and a source of industrial innovation
synchronized下的 i+=2 和 i++ i++执行结果居然不一样
Examples of using the chromium base library
【 unity】 Problems Encountered in Packaging webgl Project and their resolution Records
Bluetooth module: use problem collection
Devaxpress Chinese description --tcxpropertiesstore (property store recovery control)
[learning notes] xr872 GUI littlevgl 8.0 migration (display part)
Calculation of accuracy, recall rate, F1 value and accuracy rate of pytorch prediction results (simple implementation)
What is Google plus large text ads? How to use it?
Devaxpress Chinese description --tcximagelist (enhanced image list control)
cin,cin. get(),cin. Summary of the use of getline() and getline()
[work notes] the problem of high leakage current in standby mode of dw7888 motor driver chip
传感器:MQ-5燃气模块测量燃气值(底部附代码)
Learning notes 51 single chip microcomputer keyboard (non coding keyboard and coding keyboard, scanning mode of non coding keyboard, independent keyboard, matrix keyboard)
Huawei equipment is configured with dual reflectors to optimize the backbone layer of the virtual private network
How to solve the problem of obtaining the time through new date() and writing out the difference of 8 hours between the database and the current time [valid through personal test]
dfs与bfs解决宝岛探险