289 Star 1.4K Fork 441

GVP北京智云视图科技有限公司 / HyperLPR

 / 详情

循环调用不同的车牌号报错

待办的
缺陷
创建于  
2019-08-28 10:48

cv2.error: OpenCV(3.4.3) C:\projects\opencv-python\opencv\modules\core\src\ocl.cpp:5389: error: (-220:Unknown error code -220) OpenCL error CL_INVALID_COMMAND_QUEUE (-36) during call: clEnqueueWriteBuffer(q, handle=000000002FCEF210, CL_TRUE, offset=0, sz=8064, data=000000001947F060, 0, 0, 0) in function 'cv::ocl::OpenCLAllocator::upload'

评论 (5)

火眼 创建了缺陷

发现是在django里调用才会出现这样的问题

原因进一步确认,是在多线程环境下的问题,而且还要换图片,同一张图片没有问题,代码如下

#导入包
from hyperlpr.hyperlpr import *
#导入OpenCV库
import cv2
import random
import _thread
import time


def dd():
  #image = cv2.imread("G:\\study\\TensorFlow\\HyperLPR\\" + str(random.randint(1, 8)) + ".jpg")
  image = cv2.imread("G:\\study\\TensorFlow\\HyperLPR\\1.jpg")
  print(PR.plateRecognition(image))

while 1==1:
  _thread.start_new_thread(dd,())
  time.sleep(0.3)

大神,你是怎么解决?跪求

启动一个线程,利用redis对列,循环处理对列,这样就一个线程做处理了,避免多线程调用问题

import _thread
import cv2
from hyperlpr import HyperLPR_PlateRecogntion
from django_redis import get_redis_connection

conn = get_redis_connection()


def plate():
    i = 0
    while 1 == 1:
        try:
            msg = conn.brpop("plate")
            data = str(msg[1], encoding="utf-8").split("\t")
            image = cv2.imread(data[1])
            result = HyperLPR_PlateRecogntion(image)
            if result:
                conn.set(data[0], result[0][0] + "\t" + str(result[0][1]) + "\t" + ','.join(map(str, result[0][2])), 30)
                i += 1
            else:
                conn.set(data[0], 'error')
        except Exception as e:
            conn.set(data[0], 'error')
            print(e)
        finally:
            print("plate's count is " + str(i))


_thread.start_new_thread(plate, ())

print("plate's thread is start")```

下面就是一个调用的列子

from django.http import JsonResponse
import os
import uuid
from django_redis import get_redis_connection
import time


def number(request):
    data = {}
    if request.method == "POST":
        my_file = request.FILES.get("myfile", None)
        if not my_file:
            return JsonResponse(data)
        destination = open(os.path.join("d:\\temp", my_file.name), 'wb+')
        for chunk in my_file.chunks():
            destination.write(chunk)
        destination.close()
        image_path = "d:\\temp\\" + my_file.name
        conn = get_redis_connection()
        key = uuid.uuid4()
        conn.lpush('plate', key.__str__() + '\t' + image_path)

        for i in range(1, 100):
            res = conn.get(key)
            if res is not None:
                d = str(res, encoding="utf-8")
                if d == 'error':
                    return JsonResponse(data)
                else:
                    result = d.split("\t")
                    data = dict(res=result[0], score=float(result[1]),
                                coordinate=[int(i) for i in result[2].split(",")])
                break
            else:
                time.sleep(0.3)
        return JsonResponse(data)
    else:
        return JsonResponse(data)```

登录 后才可以发表评论

状态
负责人
项目
里程碑
Pull Requests
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
开始日期   -   截止日期
-
置顶选项
优先级
预计工期 (小时)
参与者(2)
C++
1
https://gitee.com/zeusees/HyperLPR.git
git@gitee.com:zeusees/HyperLPR.git
zeusees
HyperLPR
HyperLPR

搜索帮助