Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Commit 1d63d53

Browse files
authored
Update README.md
1 parent 6c312f5 commit 1d63d53

1 file changed

Lines changed: 20 additions & 6 deletions

File tree

tests/README.md

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,36 @@ I prefer to do such things in `ipython` or `jupyter` with `%timeit`.
2121

2222
```python
2323
import cv2
24-
from pixellink import PixelLinkDetector
24+
25+
class PixelLinkDetectorTest():
26+
""" Cut version of PixelLinkDetector """
27+
def __init__(self, xml_model_path: str):
28+
self.net = cv2.dnn.readNet(xml_model_path, xml_model_path[:-3] + 'bin')
29+
30+
def detect(self, img: 'np.ndarray') -> None:
31+
blob = cv2.dnn.blobFromImage(img, 1, (1280, 768))
32+
self.net.setInput(blob)
33+
out_layer_names = self.net.getUnconnectedOutLayersNames()
34+
return self.net.forward(out_layer_names)
35+
36+
37+
# check opencv version
38+
cv2.__version__
2539

2640
# read img and network
2741
img = cv2.imread('helloworld.png')
28-
detector = PixelLinkDetector('text-detection-0004.xml')
42+
detector = PixelLinkDetectorTest('text-detection-0004.xml')
2943

3044
# select target & backend, please read the documentation for details:
3145
# <https://docs.opencv.org/4.2.0/db/d30/classcv_1_1dnn_1_1Net.html#a9dddbefbc7f3defbe3eeb5dc3d3483f4>
32-
detector._net.setPreferableTarget(cv2.dnn.DNN_TARGET_CPU)
33-
detector._net.setPreferableBackend(cv2.dnn.DNN_BACKEND_INFERENCE_ENGINE)
46+
detector.net.setPreferableTarget(cv2.dnn.DNN_TARGET_CPU)
47+
detector.net.setPreferableBackend(cv2.dnn.DNN_BACKEND_INFERENCE_ENGINE)
3448

3549
# 1st inference does not count
36-
detector.detect(img)
50+
links, pixels = detector.detect(img)
3751

3852
# use magic function
39-
%timeit detector.detect(img)
53+
%timeit links, pixels = detector.detect(img)
4054
```
4155

4256

0 commit comments

Comments
 (0)