Closed ghost closed 6 years ago
Interesting. I had not considered images with a transparency layer. It seems like bilateralFilter
hadn't either, as they accept only 1-channel and 3-channel images. 😉
I guess you could try passing each R, G, B channel of the image separately to bilateralFilter
. Have you tried that? Not sure how it will look in the end though.
P.S. Have you seen our Google Discussion Group?
Cheers, Mike
Thank you for the response and the clever idea to filter each channel separately. I might try this. But currently I am just cutting out the black background with a face recognition tool. Which is a little bit stupid, because now I do this step twice (before and after cartoonizing)
I want to apply the Cartoonizer on a image with a transparent background. Sadly the alpha channel will always be removed and therefore all transparent parts are black after the filter was applied. Is there a workaround to fix this?
EDIT: When I read in the image with alpha channels like this: img = cv2.imread("frame004.png", cv2.IMREAD_UNCHANGED)
I get the following error:
OpenCV Error: Assertion failed ((src.type() == CV_8UC1 || src.type() == CV_8UC3) && src.type() == dst.type() && src.size() == dst.size() && src.data != dst.data) in bilateralFilter_8u, file /tmp/opencv-20161221-94455-1gogyaj/opencv-2.4.13.2/modules/imgproc/src/smooth.cpp, line 1925 Traceback (most recent call last): File "cartoonizer.py", line 17, in <module> frame_cartooned = cartoonizer.render(img) File "/Users/oliverweiss/dev/cartoonizer/filters.py", line 163, in render img_color = cv2.bilateralFilter(img_color, 9, 9, 7) cv2.error: /tmp/opencv-20161221-94455-1gogyaj/opencv-2.4.13.2/modules/imgproc/src/smooth.cpp:1925: error: (-215) (src.type() == CV_8UC1 || src.type() == CV_8UC3) && src.type() == dst.type() && src.size() == dst.size() && src.data != dst.data in function bilateralFilter_8u
Thank you!