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

python: opencv 4.5.3 ,cv2.error: OpenCV(4.5.3) C:\Users\runneradmin\AppData\Local\Temp\pip-req-build-q3d_8t8e\opencv\modules\dnn\src\model.cpp:1216: error: (-215:Assertion failed) length > FLT_EPSILON in function 'cv::dnn::TextDetectionModel_DB_Impl::unclip' #21396

Open
syly666 opened this issue Jan 5, 2022 · 2 comments
Labels
question (invalid tracker) ask questions and other "no action" items here: https://forum.opencv.org

Comments

@syly666
Copy link

syly666 commented Jan 5, 2022

System information (version)
  • OpenCV => 4.5.3
  • Operating System / Platform => Windows 10 64 Bit
  • Compiler => pycharm
Detailed description

when i use TextDetectionModel_DB in Multithreading, The exceptions are as follows

cv2.error: OpenCV(4.5.3) C:\Users\runneradmin\AppData\Local\Temp\pip-req-build-q3d_8t8e\opencv\modules\dnn\src\model.cpp:1216: error: (-215:Assertion failed) length > FLT_EPSILON in function 'cv::dnn::TextDetectionModel_DB_Impl::unclip'

when i set threadMaxNum = 1, it ok。

Is this a bug?
Please reply me. Thank you

my codes are as follows:

# !/usr/bin/python3

import threading
import os
import traceback
import cv2
import time

modelPath = "D:\\Dev_dan\\Dev_dan\\src\\main\\resources\\opencvDnnFiles\\DB_IC15_resnet18.onnx"
textModel = cv2.dnn_TextDetectionModel_DB(modelPath)
textModel.setBinaryThreshold(0.3)
textModel.setPolygonThreshold(0.5)
textModel.setMaxCandidates(200)
textModel.setUnclipRatio(2)
textModel.setInputParams(1.0/255.0, size=(736, 736), mean=(122.67891434, 116.66876762, 104.00698793))

path ="D:\\dataSet\\testfiles\\"
threadMaxNum = 2

class myThread(threading.Thread):
    def __init__(self, threadID,):
        threading.Thread.__init__(self)
        self.threadID = threadID

    def run(self):
        print("start:" + self.name)
        autoAdd(self.threadID)
        print("exit:" + self.name)

def autoAdd(threadID):
    num = 0
    files = os.listdir(path + threadID)
    while True:
        try:
            image_path = os.path.join(path+ threadID, files[num % len(files)])
            num+=1
            image = cv2.imread(image_path)
            if image is not None:
                start1 = time.time()
                result = textModel.detect(image)
                print("nums", len(result[0]))
                end1 = time.time()
                print((end1 - start1)*1000)
        except Exception as e:
            traceback.print_exc()
# create threads
threadingList = []
for i in range(0, threadMaxNum):
    thread = myThread(str(i))
    thread.start()
    threadingList.append(thread)
# start threads
for t in threadingList:
    t.join()
@alalek
Copy link
Member

alalek commented Jan 5, 2022

TextDetectionModel_DB in Multithreading

OpenCV algorithms are not thread-safe in general due to performance reasons.

Fork-based threading doesn't work properly for already multi-threaded libraries.


Usage questions should go to Users OpenCV Q/A forum: https://forum.opencv.org/

@syly666
Copy link
Author

syly666 commented Jan 5, 2022

ok, thank you. SO if i want to use TextDetectionModel in Multithreading or for Microservices, i should try to use tensorflow or other deep learning frameworks instead of OpenCV?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question (invalid tracker) ask questions and other "no action" items here: https://forum.opencv.org
Projects
None yet
Development

No branches or pull requests

2 participants