HYRY
unread,Jun 2, 2010, 1:24:31 AM6/2/10Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to ctypes-opencv
I don't know whether this is a problem of OpenCV or pyopencv.
Following is the source code
----------------------------------------------
import pyopencv as cv
import numpy as np
kernel = np.array([[1,1,1],[1,2,1],[1,1,1.0]]) * 0.1
k1 = cv.asMat(kernel, force_single_channel=True)
a = cv.Mat(5,5,cv.CV_8UC1)
a[:] = 0
b = cv.Mat()
cv.filter2D(a, b, cv.CV_8U, k1, delta=10.0)
print "==== source image ===="
print a
print "==== kernel ===="
print k1
print "==== output image ===="
print b
----------------------------------------------
It create an all zero Mat object, and filter2D() it with a kernel.
I supporse the result should be a Mat filled by 10(the delta argument
of filter2D).
But here is the output, all zeros:
==== source image ====
Mat(rows=5, cols=5, nchannels=1, depth=0):
array([[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0]], dtype=uint8)
==== kernel ====
Mat(rows=3, cols=3, nchannels=1, depth=6):
array([[ 0.1, 0.1, 0.1],
[ 0.1, 0.2, 0.1],
[ 0.1, 0.1, 0.1]])
==== output image ====
Mat(rows=5, cols=5, nchannels=1, depth=0):
array([[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0]], dtype=uint8)
if I changed:
cv.filter2D(a, b, cv.CV_8U, k1, delta=10.0)
to
cv.filter2D(a, b, cv.CV_16U, k1, delta=10.0)
the result is correct:
==== output image ====
Mat(rows=5, cols=5, nchannels=1, depth=2):
array([[10, 10, 10, 10, 10],
[10, 10, 10, 10, 10],
[10, 10, 10, 10, 10],
[10, 10, 10, 10, 10],
[10, 10, 10, 10, 10]], dtype=uint16)
or changed:
kernel = np.array([[1,1,1],[1,2,1],[1,1,1.0]]) * 0.1
to
kernel = np.array([[1,1,1],[1,2,1],[1,1,1.0]])
the result is correct:
==== source image ====
Mat(rows=5, cols=5, nchannels=1, depth=0):
array([[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0]], dtype=uint8)
==== kernel ====
Mat(rows=3, cols=3, nchannels=1, depth=6):
array([[ 1., 1., 1.],
[ 1., 2., 1.],
[ 1., 1., 1.]])
==== output image ====
Mat(rows=5, cols=5, nchannels=1, depth=0):
array([[10, 10, 10, 10, 10],
[10, 10, 10, 10, 10],
[10, 10, 10, 10, 10],
[10, 10, 10, 10, 10],
[10, 10, 10, 10, 10]], dtype=uint8)