如何将雪人形状的轮廓分成两个圆圈

问题描述

问题

我正在处理iPhone游戏中自动重播的屏幕截图,该游戏称为中国象棋(我按下 play 按钮一次,它会自动执行所有动作)。屏幕记录的速度为30FPS,并且很方便地每秒进行一次更新(30帧)。

例如,第120帧如下所示:

enter image description here

30帧(1秒)后,第150帧如下所示:

enter image description here

我想通过将前一帧与当前帧进行比较来检测所播放的每一步。我的代码在一块移动一个以上正方形的情况下起作用,但是如果它只移动一个正方形(例如上面的示例),则两个轮廓合并在一起(看起来像一个雪人):

enter image description here

(请忽略矩形)

这是我真正想要的:

enter image description here

两个单独的圆形轮廓,分别表示作品的原始正方形和作品的新正方形

请注意,由于阴影和白色环的缘故,新方块的轮廓要大于原始方块。这很重要,因为它允许我使用{{1} }

代码

cv2.contourArea

我尝试使用#prevIoUs_frame and current_frame are frames from cv2.VideoCapture() imageA = prevIoUs_frame #the original square imageB = current_frame #the new square grayA = cv2.cvtColor(imageA,cv2.COLOR_BGR2GRAY) grayB = cv2.cvtColor(imageB,cv2.COLOR_BGR2GRAY) # Structural Similarity Index (SSIM) (score,diff) = compare_ssim(grayA,grayB,full=True) diff = (diff * 255).astype("uint8") thresh = cv2.threshold(diff,255,cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)[1] (cnts,_) = cv2.findContours(thresh.copy(),cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE) #I am using openCV4 cnts.sort(key=cv2.contourArea,reverse=True) #sort by decreasing order of size cv2.drawContours(imageB,cnts,(0,255),10) #new coordinate is the largest contour,hence index 0 cv2.drawContours(imageA,1,10) #original is second largest,hence index 1 approxpolyDP,但是没有运气。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)