I am trying to add 2 different Mat objects in python. Both Mat objects are binary images (CV_8U). But because the Matrices don't have the same size, I get an error when adding them.
I generate one of the Mat objects using numpy with the proper value for the channels, like this:
diagonal = np.zeros((height,width,1))
cv2.line(diagonal,(0,0),(height,width), (255))
The other Mat object comes from cv2.Canny:
canny_edge = cv2.Canny(input_image, min_thr, max_thr)
Addition code:
final = cv2.addWeighted(canny_edge,1.0,diagonal,1.0,0)
I get the following error when I try to add the 2 Mat objects:
error: (-5) When the input arrays in add/subtract/multiply/divide functions have different types, the output array type must be explicitly specified in function cv::arithm_op
I also tried removing the channels value from the numpy generated matrix, but I got the same error.
So I tried to print the channels, but I got this:
height, weight, channels = canny_edge.shape
ValueError: not enough values to unpack (expected 3, got 2)
EDIT: I am sorry but the answer posted by Miki doesn't help me. The Mat object generated by cv2.Canny doesn't have channel information. I know it is a binary image, but opencv gets confused when it tries to add this Mat object's matrix with a Mat object which does have channel information.