1 | initial version |
ook, let's look at it:
>>> help(cv2.reduce)
Help on built-in function reduce:
reduce(...)
reduce(src, dim, rtype[, dst[, dtype]]) -> dst
. @brief Reduces a matrix to a vector.
.
. The function #reduce reduces the matrix to a vector by treating the matrix rows/columns as a set of
. 1D vectors and performing the specified operation on the vectors until a single row/column is
. obtained. For example, the function can be used to compute horizontal and vertical projections of a
. raster image. In case of #REDUCE_MAX and #REDUCE_MIN , the output image should have the same type as the source one.
. In case of #REDUCE_SUM and #REDUCE_AVG , the output may have a larger element bit-depth to preserve accuracy.
. And multi-channel arrays are also supported in these two reduction modes.
.
. The following code demonstrates its usage for a single channel matrix.
. @snippet snippets/core_reduce.cpp example
.
. And the following code demonstrates its usage for a two-channel matrix.
. @snippet snippets/core_reduce.cpp example2
.
. @param src input 2D matrix.
. a single row. 1 means that the matrix is reduced to a single column.
. @param rtype reduction operation that could be one of #ReduceTypes
. @sa repeat
why isn't there something about the dtype, above ?
but see, some REDUCE_XXX ops do support the same input and output formats:
>>> a = np.ones((10,10),np.uint8)
>>> z = cv2.reduce(a,0,cv2.REDUCE_MAX)
>>> z.dtype
dtype('uint8')
but (that's probably, what you meant):
>>> z = cv2.reduce(a,0,cv2.REDUCE_SUM)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
cv2.error: OpenCV(3.4.3) C:\projects\opencv-python\opencv\modules\core\src\matrix_operations.cpp:1111: error: (-210:Unsupported format or combination of formats) Unsupported combination of input and output array formats in function 'cv::reduce'
ok, fair point, i see, what you mean ;) also, next problem:
>>> z = cv2.reduce(a,0,cv2.REDUCE_SUM, dtype=np.int32)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: an integer is required (got type type)
ohh, it wants a CV_ type, not a numpy one, where is that documented ?
>>> z = cv2.reduce(a,0,cv2.REDUCE_SUM, dtype=cv2.CV_32S)
so, yea, as always -- docs can only get better ;)