【发布时间】:2013-10-09 12:13:43
【问题描述】:
某些视频的帧带有边框等黑色条纹。我必须将它们从框架中移除。我想出了一个粗略的解决方案:
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,也不会删除整个黑条。
这是原图:
这是运行程序后的图像:
任何人都可以提出更好的解决这个问题的建议吗? 谢谢!
【问题讨论】: