Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

多线程并发起来有些车牌无法识别到 #380

Open
clancylian opened this issue Aug 25, 2023 · 3 comments
Open

多线程并发起来有些车牌无法识别到 #380

clancylian opened this issue Aug 25, 2023 · 3 comments

Comments

@clancylian
Copy link

采用python flask做成服务接口,如果在构造函数中新建车牌识别对象,然后在接口中调用车牌识别函数,当并发起来时,有些车牌无法识别到,但是将这些无法识别的车牌,用单张调用接口,可以识别到,是因为不支持多线程吗?

@qianxiaoer
Copy link

qianxiaoer commented Aug 25, 2023 via email

@tunmx
Copy link
Collaborator

tunmx commented Aug 25, 2023

能把调用方法的代码片段分享一下吗

@clancylian
Copy link
Author

clancylian commented Aug 28, 2023

class PlateDetector():

detector = None

def __init__(self, level='high'):
    self.detector = lpr3.LicensePlateCatcher(detect_level=lpr3.DETECT_LEVEL_HIGH if level=='high' else lpr3.DETECT_LEVEL_LOW)

def format_plate(self, plate):
    plate_type = type_list[plate[2]]
    if plate_type == '绿牌新能源' and not plate[0][2].isalpha():
        plate_type = '蓝牌'
    return { 
                'hphm' : plate[0],
                'hpwz' : ",".join([str(c)for c in plate[3]]),
                'hpzl' : plate_type,
                'kxd' : '%.2f' % (plate[1])
            }

def detect(self, img_b64, roi):
    image = conv_b64str_2_img(img_b64)
    result = self.detector(image)
    return [    
        self.format_plate(plate) 
        for plate in result if roi==[] or box_is_within_poly(plate[3], roi, 'ct')
    ]

def main():

opt = parse_opt()
global PD,
print('[INIT] Detectors : Initializing ... ', end='', flush=True)
PD = PlateDetector()
print('Done.')

    
app.run(host=opt.host, port=opt.port, debug=False)

@app.route(API_ROUTE + '/detect_plates', methods=['POST'])
@register_handler('request', 'json', True, 'POST')
@register_handler('data', 'detect')
def detect_plates(data):

count, images= data.get('count'), data.get('images')
images_result = { k : PD.detect( images[k].get('image'), DM.check_parking_roi(images[k].get('parkingid')) if APPLY_ROI else []) for k in images}
return { 'count' : count, 'images' : images_result }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants