使用cv2.fillConvexPoly时cv2.LINE_AA无法实现抗锯齿边缘求助
问题:cv2.fillConvexPoly的LINE_AA抗锯齿参数未生效
我想用cv2.fillConvexPoly绘制带抗锯齿边缘的多边形,设置了lineType=cv2.LINE_AA参数,但完全没达到预期效果。
以下是我的测试代码:
import numpy as np import cv2 import matplotlib.pyplot as plt plt.subplot(2, 3, 1) mask = np.zeros((80, 50), dtype=np.float32) polygon_arr = (np.array([[10, 16],[26, 20],[31, 50],[14, 50]])).astype(np.int32) cv2.fillConvexPoly(mask, polygon_arr, 1, lineType=cv2.LINE_4) plt.imshow(mask, cmap='gray') plt.title('1, LINE_4') plt.subplot(2, 3, 2) mask = np.zeros((80, 50), dtype=np.float32) polygon_arr = (np.array([[10, 16],[26, 20],[31, 50],[14, 50]])).astype(np.int32) cv2.fillConvexPoly(mask, polygon_arr, 1, lineType=cv2.LINE_8) plt.imshow(mask, cmap='gray') plt.title('1, LINE_8') plt.subplot(2, 3, 3) mask = np.zeros((80, 50), dtype=np.float32) polygon_arr = (np.array([[10, 16],[26, 20],[31, 50],[14, 50]])).astype(np.int32) cv2.fillConvexPoly(mask, polygon_arr, 1, lineType=cv2.LINE_AA) plt.imshow(mask, cmap='gray') plt.title('1, LINE_AA') plt.subplot(2, 3, 4) mask = np.zeros((80, 50), dtype=np.float32) polygon_arr = (np.array([[10, 16],[26, 20],[31, 50],[14, 50]])).astype(np.int32) cv2.fillConvexPoly(mask, polygon_arr, 255, lineType=cv2.LINE_4) plt.imshow(mask, cmap='gray') plt.title('255, LINE_4') plt.subplot(2, 3, 5) mask = np.zeros((80, 50), dtype=np.float32) polygon_arr = (np.array([[10, 16],[26, 20],[31, 50],[14, 50]])).astype(np.int32) cv2.fillConvexPoly(mask, polygon_arr, 255, lineType=cv2.LINE_8) plt.imshow(mask, cmap='gray') plt.title('255, LINE_8') plt.subplot(2, 3, 6) mask = np.zeros((80, 50), dtype=np.float32) polygon_arr = (np.array([[10, 16],[26, 20],[31, 50],[14, 50]])).astype(np.int32) cv2.fillConvexPoly(mask, polygon_arr, 255, lineType=cv2.LINE_AA) plt.imshow(mask, cmap='gray') plt.title('255, LINE_AA') plt.show()
测试中不管用LINE_4、LINE_8还是LINE_AA,输出结果完全一致。我还尝试把数组的dtype改成int32,问题依然存在。测试效果截图:
内容的提问来源于stack exchange,提问作者Citrus Aqua
相关产品推荐
相关产品推荐

