Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 2.7 如何删除旋转&;周围的黑色边框;结果是什么?OpenCv Python_Python 2.7_Opencv_Image Processing_Image Rotation_Imutils - Fatal编程技术网

Python 2.7 如何删除旋转&;周围的黑色边框;结果是什么?OpenCv Python

Python 2.7 如何删除旋转&;周围的黑色边框;结果是什么?OpenCv Python,python-2.7,opencv,image-processing,image-rotation,imutils,Python 2.7,Opencv,Image Processing,Image Rotation,Imutils,我的任务是为深度学习生成数据。我拍摄种子图像,旋转它们并在背景上随机绘制它们。问题是旋转会导致图像周围出现折线边界,我不知道为什么会出现,也不知道如何消除它 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[ro

我的任务是为深度学习生成数据。我拍摄种子图像,旋转它们并在背景上随机绘制它们。问题是旋转会导致图像周围出现折线边界,我不知道为什么会出现,也不知道如何消除它

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
代码说明:默认值是种子图像中的背景色。旋转会生成一个黑色区域,我用默认值覆盖它

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


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

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使用这些函数,您共享的链接正是我遵循的链接,因为这种方法直接在一些旋转中切割种子。它也没有解决边界问题,因为它仍然存在(