简体   繁体   English

分割黑色和移动像素

[英]Segment black AND moving Pixels

I'm trying to segment the moving propeller of this Video.我正在尝试分割此视频的移动螺旋桨。 My approach is, to detect all black and moving pixels to separate the propeller from the rest.我的方法是,检测所有黑色和移动像素,将螺旋桨与 rest 分开。 Here is what I tried so far:这是我到目前为止所尝试的:

import numpy as np
import cv2


x,y,h,w = 350,100,420,500 # Croping values


cap = cv2.VideoCapture('Video Path')
  

while(1):        
    _, frame = cap.read() 
    
    frame = frame[y:y+h, x:x+w] # Crop Video
    
    hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) 
    lower_black = np.array([0,0,0]) 
    upper_black = np.array([360,255,90]) 
    mask = cv2.inRange(hsv, lower_black, upper_black) 
    res = cv2.bitwise_and(frame,frame, mask= mask) 
    
    nz = np.argwhere(mask)
                                
            
    cv2.imshow('Original',frame)
    cv2.imshow('Propeller Segmentation',mask)
  
    k = cv2.waitKey(30) & 0xff # press esc to exit
    if k == 27:
        break

cap.release()
cv2.destroyAllWindows()

Screenshot form the Video视频截图

Result of the Segmentation分割结果

With function cv.createBackgroundSubtractorMOG2()使用 function cv.createBackgroundSubtractorMOG2()

I think you should have a look at background subtraction.我认为你应该看看背景减法。 It should be the right approach for your problem.这应该是解决您的问题的正确方法。

OpenCV provides a good tutorial on this: Link OpenCV 提供了一个很好的教程: 链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM