凸轮移位闭塞 [英] Occlusion with camshift

查看:78
本文介绍了凸轮移位闭塞的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过camshift算法进行对象跟踪.目前,我正在使用内置的opencv代码,其中无法处理遮挡.

I am working on object tracking by camshift algorithm. For the time being I am using the inbuilt opencv code wherein I have trouble dealing with occlusion.

  hsv = cv2.cvtColor(self.frame, cv2.COLOR_BGR2HSV)
  mask = cv2.inRange(hsv, np.array((0., 60., 32.)), np.array((180., 255., 255.)))
  prob = cv2.calcBackProject([hsv], [0], self.hist, [0, 180], 1)
  cv2.imshow('prob_0',prob)
  prob &= mask
  cv2.imshow('prob',prob)
  term_crit = ( cv2.TERM_CRITERIA_EPS | cv2.TERM_CRITERIA_COUNT, 10, 1 )
  track_box, self.track_window = cv2.CamShift(prob, self.track_window, term_crit)

我的问题是在这段代码中,当我的红球对象超出相机的视野时,或者如果我用手遮住了球的一部分,则会崩溃并给出以下错误:

My problem is that in this code when my object which is a red ball goes out of the field of vision of the camera or if I cover some portion of the ball with my hand, then it crashes and give the error that:

   track_box, self.track_window = cv2.CamShift(prob, self.track_window, term_crit)
   error: ..\..\..\..\opencv\modules\video\src\camshift.cpp:80: error: (-5) Input           
   window has non-positive sizes in function cvMeanShift

这是因为我对cv2.Camshift->的参数"prob"没有对应于我的球的任何值(prob是获得的包含阈值球的二进制图像)

This is because my parameter to cv2.Camshift -> which is "prob" is not having any values corresponding to my ball (prob is the binary image obtained which consists of the thresholded ball)

在这种情况下,我有一个解决遮挡的想法.就是将球矩阵存储在全局变量中,如果相机的当前帧无法获得球矩阵,则应使用全局变量代替它,直到找不到并跟踪球为止.那么如何在给定的代码中应用这种逻辑呢?

I have one idea for dealing with occlusion in this scenario. It's that I'll store the ball matrix in a global variable and if my camera's current frame cannot obtain the ball matrix then it should use the global variable instead of it till it doesn't find and track the ball. So how to apply this logic in the given code?

任何人都可以帮助我在这种情况下如何解决阻塞问题.

So can anyone help me how to deal with the occlusion in this ball situation.

推荐答案

在OpenCV中,当没有对象可跟踪时,我也遇到了程序卡住的问题.后来我解决了.

In OpenCV, I faced the same problem of the program getting stuck when there was no object to track. Later I solved it.

要解决它:

1)首先计算meanShift,它返回收敛所需的迭代次数.2)如果(iteration_meanShift!= 0),则计算CamShift并返回bounding_box + frame.否则,只返回框架.

1) First calculate meanShift, which returns the number of iterations it took to converge. 2) if (iteration_meanShift != 0), then calculate the CamShift and return bounding_box+frame. Else, return only the frame.

即当且仅当meanshift非零时,才计算camshift,否则不计算camshift.

i.e. if and only if meanshift is non-zero, calculate the camshift, else don't calculate the camshift.

这篇关于凸轮移位闭塞的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆