Skip to content

Commit 22dece8

Browse files
committed
Fix DNN samples for compatibility with Python 3.
Add PyInt_Check in pyopencv_dnn.hpp.
1 parent 1ba29cc commit 22dece8

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

modules/dnn/misc/python/pyopencv_dnn.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ bool pyopencv_to(PyObject *o, dnn::DictValue &dv, const char *name)
1616
dv = dnn::DictValue((int64)PyLong_AsLongLong(o));
1717
return true;
1818
}
19+
else if (PyInt_Check(o))
20+
{
21+
dv = dnn::DictValue((int64)PyInt_AS_LONG(o));
22+
return true;
23+
}
1924
else if (PyFloat_Check(o))
2025
{
2126
dv = dnn::DictValue(PyFloat_AS_DOUBLE(o));

samples/dnn/colorization.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# Script is based on https://github.com/richzhang/colorization/colorize.py
1+
# Script is based on https://github.com/richzhang/colorization/blob/master/colorize.py
2+
# To download the caffemodel and the prototxt, see: https://github.com/richzhang/colorization/tree/master/models
3+
# To download pts_in_hull.npy, see: https://github.com/richzhang/colorization/blob/master/resources/pts_in_hull.npy
24
import numpy as np
35
import argparse
46
import cv2 as cv
@@ -27,8 +29,8 @@ def parse_args():
2729

2830
# populate cluster centers as 1x1 convolution kernel
2931
pts_in_hull = pts_in_hull.transpose().reshape(2, 313, 1, 1)
30-
net.getLayer(long(net.getLayerId('class8_ab'))).blobs = [pts_in_hull.astype(np.float32)]
31-
net.getLayer(long(net.getLayerId('conv8_313_rh'))).blobs = [np.full([1, 313], 2.606, np.float32)]
32+
net.getLayer(net.getLayerId('class8_ab')).blobs = [pts_in_hull.astype(np.float32)]
33+
net.getLayer(net.getLayerId('conv8_313_rh')).blobs = [np.full([1, 313], 2.606, np.float32)]
3234

3335
if args.input:
3436
cap = cv.VideoCapture(args.input)

samples/dnn/mobilenet_ssd_python.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@
9595
else:
9696
cropSize = (cols, int(cols / WHRatio))
9797

98-
y1 = (rows - cropSize[1]) / 2
98+
y1 = int((rows - cropSize[1]) / 2)
9999
y2 = y1 + cropSize[1]
100-
x1 = (cols - cropSize[0]) / 2
100+
x1 = int((cols - cropSize[0]) / 2)
101101
x2 = x1 + cropSize[0]
102102
frame = frame[y1:y2, x1:x2]
103103

samples/dnn/resnet_ssd_face_python.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import numpy as np
22
import argparse
3-
import os
4-
import sys
5-
sys.path.append('/home/arrybn/build/opencv/lib')
63
import cv2 as cv
74
try:
85
import cv2 as cv

0 commit comments

Comments
 (0)