当前位置:网站首页>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},边栏推荐
- Combining strings and numbers using ssstream
- Devaxpress Chinese description --tcxpropertiesstore (property store recovery control)
- Mac使用Docker安装Oracle
- Alertwindowmanager pop up prompt window help (Part 1)
- Vs how to enter chromium subprocess debugging
- STM32 sensorless brushless motor drive
- Pytoch freeze pre training weights (feature extraction and BN layer)
- Application and examples of C language structure
- Interruption of 51 single chip microcomputer learning notes (external interruption, timer interruption, interrupt nesting)
- STM32F103 IIC OLED program migration complete engineering code
猜你喜欢
![[learning notes] xr872 GUI littlevgl 8.0 migration (display part)](/img/5e/fc8c3fe3029c36648fbc3f48bc0c2f.jpg)
[learning notes] xr872 GUI littlevgl 8.0 migration (display part)

Establishment of microservice development environment

Stm32 mpu6050 servo pan tilt support follow

Ruixing coffee moves towards "national consumption"

Mac使用Docker安装Oracle

How does Google's audience work?

分享三个关于CMDB的小故事

What is the path field—— Competitive advertising

Ruixing coffee 2022, extricating itself from difficulties and ushering in a smooth path

SQLserver2008 拒绝了对对象 '****' (数据库 '****',架构 'dbo')的 SELECT 权限
随机推荐
Implementation of pointer linked list
VI keyboard diagram
1、 Set up Django automation platform (realize one click SQL execution)
STM32 external interrupt Usage Summary
Delphi7 compressed pictures (BMP, JPG, PNG)
Devaxpress Chinese description --tcxpropertiesstore (property store recovery control)
When AI meets music, iFLYTEK music leads the industry reform with technology
Simple ranging using Arduino and ultrasonic sensors
Installing Oracle with docker for Mac
[printf function and scanf function] (learning note 5 -- standard i/o function)
Devaxpress Chinese description -- tdxgallerycontrol object (gallery component)
Why is Huawei matebook x Pro 2022 leading a "laptop" revolution
一、搭建django自动化平台(实现一键执行sql)
General IP address, account and password of mobile IPv6 optical cat login, and mobile optical cat is in bridging mode
Vscode configuration header file -- Take opencv and its own header file as an example
Restrict cell input type and display format in CXGRID control
PyFlink实现自定义SourceFunction
Ruixing coffee moves towards "national consumption"
Decompression and compression of chrome resource file Pak
记录:如何解决MultipartFile类的transferTo()上传图片报“系统找不到指定的路径“问题【亲测有效】