在本地视频上模拟视频损坏,以创建数据集[关闭]

问题描述 投票:-1回答:1

[我想模拟由于像素化而损坏的视频,就像从皮尔斯·杰克逊Example of pixelation中的下图看到的那样>

我正在尝试创建模型以检查图像是否具有此像素化。

[请不要让我在本地拥有良好的图像/视频,而我需要为此努力。我已经尝试过将图像的某些部分裁剪并粘贴到主图像的顶部,但是对于原始图像来说,它还不够好。enter image description here如上所示

这是我的职责

def subimage(image,id, center, theta):

   originalimage=image
   pureimage=image
   # Uncomment for theta in radians
   #theta *= 180/np.pi

   flag=0
   j=0

   for j in range(random.randint(5,50)):
        flag=0
        for i in range(random.randint(5,50)):
                #originalimage=pureimage
                shape = ( image.shape[1], image.shape[0] ) # cv2.warpAffine expects shape in (length, height)
                matrix = cv2.getRotationMatrix2D( center=center, angle=theta, scale=1 )
                '''warpaffine just rotates the image'''
                image = cv2.warpAffine( src=pureimage, M=matrix, dsize=shape )
                #cv2.imshow("frame",image)
                #cv2.waitKey(0)
                '''cropping defined part based on array slices'''    
                try:
                    width=random.randint(5,originalimage.shape[1]/4)
                    height=random.randint(5,originalimage.shape[0]/4)
                    x = random.randint(4,originalimage.shape[1]-width)
                    y = random.randint(4,originalimage.shape[0]-height)
                    image_cropped = image[ y:height,x:width ]
                    #cv2.imshow("frame",image_cropped)
                    #cv2.waitKey(2000)
                    x_offset=random.randint(4,originalimage.shape[1]-image_cropped.shape[1])
                    y_offset=random.randint(4,originalimage.shape[0]-image_cropped.shape[0])
                    originalimage[y_offset:y_offset+image_cropped.shape[0], x_offset:x_offset+image_cropped.shape[1]] = image_cropped
                    #cv2.imwrite(os.path.join(directory, 'blocked'+str(count)+".jpg"), originalimage)
                    #count+=1

                except Exception as e:
                    #logging.info('Exception Details', 'division', exc_info=e)
                    if(flag==0):
                        cv2.imwrite(os.path.join(directory, 'blocked'+str(id)+".jpg"), originalimage)
                        #count+=1
                    else:
                        flag=1
                    #count+=1
   if(flag==0):
    cv2.imwrite(os.path.join(directory, 'blocked_final'+str(id)+'.jpg'), originalimage)
   return originalimage

我该如何纠正此代码

我想模拟视频因像素化而损坏,正如您从Piercy Jackson的以下图像中看到的那样,我正在尝试创建一个模型来检查图像是否具有这种像素化。 ...

python opencv machine-learning mpeg video-compression
1个回答
0
投票

您尝试模拟的“像素化”损坏不是一个随机过程,它与视频文件的压缩然后解码的方式紧密相关。这些“像素化”是解码过程中的“缺陷”。为了模拟它们,您需要深入研究视频解码过程,并查看这些错误的来源。根据解码期间发生的问题的类型,您可以有几种类型的“像素化”。您可能已损坏关键帧,解码后的帧与为该帧编码的估计运动之间的未对准等。

© www.soinside.com 2019 - 2024. All rights reserved.