JeVoisBase  1.21
JeVois Smart Embedded Machine Vision Toolkit Base Modules
Share this page:
Loading...
Searching...
No Matches
db.py
Go to the documentation of this file.
1# This file is part of OpenCV Zoo project.
2# It is subject to the license terms in the LICENSE file found in the same directory.
3#
4# Copyright (C) 2021, Shenzhen Institute of Artificial Intelligence and Robotics for Society, all rights reserved.
5# Third party copyrights are property of their respective owners.
6
7import numpy as np
8import cv2 as cv
9
10class DB:
11 def __init__(self, modelPath, inputSize=[736, 736], binaryThreshold=0.3, polygonThreshold=0.5, maxCandidates=200, unclipRatio=2.0, backendId=0, targetId=0):
12 self._modelPath = modelPath
13 self._model = cv.dnn_TextDetectionModel_DB(
14 cv.dnn.readNet(self._modelPath)
15 )
16
17 self._inputSize = tuple(inputSize) # (w, h)
18 self._inputHeight = inputSize[0]
19 self._inputWidth = inputSize[1]
20 self._binaryThreshold = binaryThreshold
21 self._polygonThreshold = polygonThreshold
22 self._maxCandidates = maxCandidates
23 self._unclipRatio = unclipRatio
24 self._backendId = backendId
25 self._targetId = targetId
26
27 self._model.setPreferableBackend(self._backendId)
28 self._model.setPreferableTarget(self._targetId)
29
30 self._model.setBinaryThreshold(self._binaryThreshold)
31 self._model.setPolygonThreshold(self._polygonThreshold)
32 self._model.setUnclipRatio(self._unclipRatio)
33 self._model.setMaxCandidates(self._maxCandidates)
34
35 self._model.setInputParams(1.0/255.0, self._inputSize, (122.67891434, 116.66876762, 104.00698793))
36
37 @property
38 def name(self):
39 return self.__class__.__name__
40
41 def setBackend(self, backend):
42 self._backendId = backend
43 self._model.setPreferableBackend(self._backendId)
44
45 def setTarget(self, target):
46 self._targetId = target
47 self._model.setPreferableTarget(self._targetId)
48
49 def setInputSize(self, input_size):
50 self._inputSize = tuple(input_size)
51 self._model.setInputParams(1.0/255.0, self._inputSize, (122.67891434, 116.66876762, 104.00698793))
52
53 def infer(self, image):
54 assert image.shape[0] == self._inputSize[1], '{} (height of input image) != {} (preset height)'.format(image.shape[0], self._inputSize[1])
55 assert image.shape[1] == self._inputSize[0], '{} (width of input image) != {} (preset width)'.format(image.shape[1], self._inputSize[0])
56
57 return self._model.detect(image)
58
Definition db.py:10
setTarget(self, target)
Definition db.py:45
__init__(self, modelPath, inputSize=[736, 736], binaryThreshold=0.3, polygonThreshold=0.5, maxCandidates=200, unclipRatio=2.0, backendId=0, targetId=0)
Definition db.py:11
_inputWidth
Definition db.py:19
_model
Definition db.py:13
_targetId
Definition db.py:25
_polygonThreshold
Definition db.py:21
_binaryThreshold
Definition db.py:20
_backendId
Definition db.py:24
infer(self, image)
Definition db.py:53
_maxCandidates
Definition db.py:22
_inputHeight
Definition db.py:18
name(self)
Definition db.py:38
_modelPath
Definition db.py:12
setBackend(self, backend)
Definition db.py:41
setInputSize(self, input_size)
Definition db.py:49
_inputSize
Definition db.py:17
_unclipRatio
Definition db.py:23