Kinect在Raspberry Pi上进行对象跟踪 [英] Object tracking by kinect on raspberry pi

查看:509
本文介绍了Kinect在Raspberry Pi上进行对象跟踪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用树莓派上的kinect进行对象跟踪. 我混合使用2个代码,因为我需要用kinect查找几乎对象,然后在跟踪灰色对象的过程之后使用OpenCV滤镜设置灰色! 但是我不能!请帮助我

I m working on object tracking with kinect on a raspberry pi. I mix 2 code because I need to find nearly object with kinect and then use OpenCV filter to setup gray color after this process tracking gray object! but I can't! please help me

import freenect
import cv2
import numpy as np

"""
Grabs a depth map from the Kinect sensor and creates an image from it.
"""
def getDepthMap():  
depth, timestamp = freenect.sync_get_depth()

np.clip(depth, 0, 2**10 - 1, depth)
depth >>= 2
depth = depth.astype(np.uint8)

return depth

while True:
depth = getDepthMap()
#text_file = codecs.open("log2.txt", "a","utf-8-sig")
#text_file.write(str(depth)+'\n')

depth = getDepthMap()
blur = cv2.GaussianBlur(depth, (5, 5), 0)
cv2.imshow('image', blur)

此代码可以向我显示2种颜色的对象:黑白 黑色几乎- 我想将这段代码混合到对象跟踪中.但很结冰.

This code can show me object in 2 color : black and white black is nearly --- I want to mix this code to object tracking. but icant.

# find contours in the mask and initialize the current
# (x, y) center of the ball
cnts = cv2.findContours(mask.copy(), cv2.RETR_EXTERNAL,
    cv2.CHAIN_APPROX_SIMPLE)[-2]
center = None

# only proceed if at least one contour was found
if len(cnts) > 0:
    # find the largest contour in the mask, then use
    # it to compute the minimum enclosing circle and
    # centroid
    c = max(cnts, key=cv2.contourArea)
    ((x, y), radius) = cv2.minEnclosingCircle(c)
    M = cv2.moments(c)
    center = (int(M["m10"] / M["m00"]), int(M["m01"] / M["m00"]))

    # only proceed if the radius meets a minimum size
    if radius > 10:
        # draw the circle and centroid on the frame,
        # then update the list of tracked points
        cv2.circle(frame, (int(x), int(y)), int(radius),
            (0, 255, 255), 2)
        cv2.circle(frame, center, 5, (0, 0, 255), -1)

# update the points queue
pts.appendleft(center)

http://www.pyimagesearch.com/2015/09/14/ball-tracking-with-opencv/

推荐答案

代码中的逻辑似乎是正确的.不过,我注意到一些实现错误.

The logic in your code seems to be right. I noticed some implementation errors, though.

首先,您应该在while True之后缩进该块.您还应该添加对waitKey()的调用,以使OpenCV不会卡在imshow()上:

First, you should indent the block after while True. You should also add a call to waitKey() so that OpenCV doesn't get stuck at imshow():

while True:
    depth = getDepthMap()
    blur = cv2.GaussianBlur(depth, (5, 5), 0)
    cv2.imshow('image', blur)
    cv2.waitKey(1)

最后,您应该将下一个块(mask)的输入与上一个块(blur)的输出关联:

Finally, you should associate the input of the next block (mask) with the output of the previous one (blur):

mask = blur

这篇关于Kinect在Raspberry Pi上进行对象跟踪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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