【问题标题】:How to remove the black border around rotated & masked image in result? OpenCv Python如何在结果中删除旋转和蒙版图像周围的黑色边框? OpenCv Python
【发布时间】:2019-10-20 15:01:29
【问题描述】:

我的任务是为深度学习生成数据。我拍摄种子图像,旋转它们并在背景上随机绘制它们。问题是旋转导致图像周围出现虚线边界,我无法弄清楚它出现的原因或如何摆脱它。

def rotateSeed(img):
rotated = imutils.rotate_bound(img, randint(0,360))
for row in range(rotated.shape[0]):
    for col in range(rotated.shape[1]):
        if (rotated[row,col,0] == 0) and (rotated[row,col,1] == 0) and (rotated[row,col,2] == 0):
            rotated[row,col] = default[0,0]
return rotated

代码说明:默认为种子图片的背景色。旋转会产生一个我用默认值覆盖的黑色区域。

只有一个人遇到过这个问题,解决方案并不能解释太多。它甚至没有旋转:OpenCV

Original seed image Rotated seed image

【问题讨论】:

标签: python-2.7 opencv image-processing image-rotation imutils


【解决方案1】:

您可以使用此代码进行旋转:

import cv2
import numpy as np

img = cv2.imread('C:\\Code\\1.jpeg')
num_rows, num_cols = img.shape[:2]

rotation_matrix = cv2.getRotationMatrix2D((num_cols/2, num_rows/2), 30, 1)
img_rotation = cv2.warpAffine(img, rotation_matrix, (num_cols, num_rows))
cv2.imshow('Rotation', img_rotation)
cv2.waitKey()

【讨论】:

  • 亲爱的 Andy_101,在幕后 imutils 使用了这些功能,而您分享的链接正是我遵循的链接,因为这种方法在某些旋转中直接切割种子。它也没有解决边界问题,因为它仍然存在。 :(
猜你喜欢
  • 2017-10-28
  • 1970-01-01
  • 2018-11-16
  • 1970-01-01
  • 2010-09-08
  • 1970-01-01
  • 2018-06-18
  • 2021-09-09
  • 1970-01-01
相关资源
最近更新 更多