某些視頻的框架具有黑色邊框,如邊框。我必須從框架中刪除它們。我想出了一個粗液:從Python中的圖像中刪除邊框
import sys, cv2, numpy
import Image, scipy
filename = "snap.jpeg"
img = cv2.imread(filename)
def checkEqual(lst):
return len(set(lst)) <= 1 ## <-- This is the maximum length of the set
def removeColumns(image):
for col in range(image.shape[1]):
for ch in range(3):
try:
checkEqual(image[:, col, ch].tolist())
except IndexError:
continue
else:
if checkEqual(image[:, col, ch].tolist()):
try:
image = numpy.delete(image, col, 1)
except IndexError:
continue
else:
pass
return image
img2 = removeColumns(img)
print img.shape, img2.shape ## (480, 856, 3) (480, 705, 3)
在這裏,我發現有相同的元素和所有我有黑色邊框的影片列。但即使我將函數checkEqual()
中的最大長度從1增加到20或40,整個黑色條紋也不會被刪除。
這是原始圖像:
這是運行該程序後的圖像:
誰能給建議了一個更好的辦法解決這個問題? 謝謝!
T母雞是什麼?保存在哪裏? –