hopefully fixed handling of 'long' Python type in OpenCV bindings (bug #2193). added the corresponding test
This commit is contained in:
parent
2320ec76b4
commit
4044fbcb33
@ -476,7 +476,12 @@ static bool pyopencv_to(PyObject* obj, int& value, const char* name = "<unknown>
|
|||||||
(void)name;
|
(void)name;
|
||||||
if(!obj || obj == Py_None)
|
if(!obj || obj == Py_None)
|
||||||
return true;
|
return true;
|
||||||
value = (int)PyInt_AsLong(obj);
|
if(PyInt_Check(obj))
|
||||||
|
value = (int)PyInt_AsLong(obj);
|
||||||
|
else if(PyLong_Check(obj))
|
||||||
|
value = (int)PyLong_AsLong(obj);
|
||||||
|
else
|
||||||
|
return false;
|
||||||
return value != -1 || !PyErr_Occurred();
|
return value != -1 || !PyErr_Occurred();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -741,7 +746,14 @@ template<typename _Tp> struct pyopencvVecConverter
|
|||||||
PyObject* item_ij = items_i[j];
|
PyObject* item_ij = items_i[j];
|
||||||
if( PyInt_Check(item_ij))
|
if( PyInt_Check(item_ij))
|
||||||
{
|
{
|
||||||
int v = PyInt_AsLong(item_ij);
|
int v = (int)PyInt_AsLong(item_ij);
|
||||||
|
if( v == -1 && PyErr_Occurred() )
|
||||||
|
break;
|
||||||
|
data[j] = saturate_cast<_Cp>(v);
|
||||||
|
}
|
||||||
|
else if( PyLong_Check(item_ij))
|
||||||
|
{
|
||||||
|
int v = (int)PyLong_AsLong(item_ij);
|
||||||
if( v == -1 && PyErr_Occurred() )
|
if( v == -1 && PyErr_Occurred() )
|
||||||
break;
|
break;
|
||||||
data[j] = saturate_cast<_Cp>(v);
|
data[j] = saturate_cast<_Cp>(v);
|
||||||
|
@ -42,6 +42,11 @@ class Hackathon244Tests(NewOpenCVTests):
|
|||||||
self.assert_(cv2.norm(a, cv2.NORM_L1) == 15)
|
self.assert_(cv2.norm(a, cv2.NORM_L1) == 15)
|
||||||
absa1 = cv2.absdiff(a, 0)
|
absa1 = cv2.absdiff(a, 0)
|
||||||
self.assert_(cv2.norm(absa1, absa0, cv2.NORM_INF) == 0)
|
self.assert_(cv2.norm(absa1, absa0, cv2.NORM_INF) == 0)
|
||||||
|
|
||||||
|
def test_imencode(self):
|
||||||
|
a = np.zeros((480, 640), dtype=np.uint8)
|
||||||
|
flag, ajpg = cv2.imencode("img_q90.jpg", a, [cv2.IMWRITE_JPEG_QUALITY, 90])
|
||||||
|
self.assert_(flag == True and ajpg.dtype == np.uint8 and ajpg.shape[0] > 1 and ajpg.shape[1] == 1)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
print "testing", cv.__version__
|
print "testing", cv.__version__
|
||||||
|
Loading…
Reference in New Issue
Block a user