如何同步线程以捕获相同数量的帧?
Posted
技术标签:
【中文标题】如何同步线程以捕获相同数量的帧?【英文标题】:How to synchronize threads to capture same number of frames? 【发布时间】:2012-12-09 02:58:30 【问题描述】:我正在开发 Kinect 应用程序。我有两个线程,一个用于读取关节的值(包含 20 个关节的 x、y、z 坐标),另一个用于读取深度值(每帧 76800 个短值)。我从按下开始按钮开始记录这些值,直到按下结束按钮。我希望编写相同数量的关节和深度帧,但我总是以很多关节帧结束。我捕获了 150 个深度帧但 180 个关节帧,我认为这是因为深度写入缓冲区的数据量。联合只在每帧中写入 60 个浮点数,但深度为 76800 短裤。
如何从每个捕获相同数量的帧? (Kinect 捕捉深度和坐标 25 到 30 FPS)
此日志还显示了每个调用的线程数不相等:
112/11/9 4:19:58: SKELETON
112/11/9 4:19:58: DEPTH
112/11/9 4:19:58: SKELETON
112/11/9 4:19:58: SKELETON
112/11/9 4:19:58: DEPTH
112/11/9 4:19:58: SKELETON
112/11/9 4:19:59: DEPTH
112/11/9 4:19:59: DEPTH
112/11/9 4:19:59: SKELETON
112/11/9 4:19:59: SKELETON
112/11/9 4:19:59: SKELETON
112/11/9 4:19:59: DEPTH
112/11/9 4:19:59: DEPTH
112/11/9 4:19:59: SKELETON
112/11/9 4:19:59: SKELETON
112/11/9 4:19:59: DEPTH
112/11/9 4:19:59: SKELETON
112/11/9 4:19:59: SKELETON
112/11/9 4:19:59: SKELETON
112/11/9 4:19:59: SKELETON
112/11/9 4:19:59: DEPTH
112/11/9 4:19:59: SKELETON
112/11/9 4:19:59: DEPTH
112/11/9 4:19:59: SKELETON
112/11/9 4:19:59: SKELETON
112/11/9 4:19:59: DEPTH
112/11/9 4:19:59: SKELETON
112/11/9 4:19:59: DEPTH
112/11/9 4:19:59: DEPTH
112/11/9 4:19:59: SKELETON
112/11/9 4:19:59: SKELETON
112/11/9 4:19:59: DEPTH
112/11/9 4:20:0: SKELETON
112/11/9 4:20:0: SKELETON
112/11/9 4:20:0: SKELETON
112/11/9 4:20:0: DEPTH
112/11/9 4:20:0: SKELETON
112/11/9 4:20:0: DEPTH
112/11/9 4:20:0: DEPTH
112/11/9 4:20:0: SKELETON
112/11/9 4:20:0: SKELETON
112/11/9 4:20:0: DEPTH
112/11/9 4:20:0: SKELETON
112/11/9 4:20:0: DEPTH
112/11/9 4:20:0: SKELETON
112/11/9 4:20:0: DEPTH
112/11/9 4:20:0: SKELETON
112/11/9 4:20:0: DEPTH
112/11/9 4:20:0: SKELETON
112/11/9 4:20:0: SKELETON
112/11/9 4:20:0: SKELETON
112/11/9 4:20:0: SKELETON
112/11/9 4:20:0: DEPTH
112/11/9 4:20:0: SKELETON
112/11/9 4:20:0: DEPTH
112/11/9 4:20:0: SKELETON
112/11/9 4:20:0: SKELETON
112/11/9 4:20:0: SKELETON
112/11/9 4:20:1: SKELETON
112/11/9 4:20:1: DEPTH
112/11/9 4:20:1: DEPTH
112/11/9 4:20:1: SKELETON
112/11/9 4:20:1: SKELETON
112/11/9 4:20:1: DEPTH
112/11/9 4:20:1: SKELETON
112/11/9 4:20:1: DEPTH
112/11/9 4:20:1: SKELETON
112/11/9 4:20:1: DEPTH
112/11/9 4:20:1: DEPTH
112/11/9 4:20:1: SKELETON
112/11/9 4:20:1: SKELETON
112/11/9 4:20:1: SKELETON
112/11/9 4:20:1: DEPTH
112/11/9 4:20:1: DEPTH
112/11/9 4:20:1: DEPTH
112/11/9 4:20:1: SKELETON
112/11/9 4:20:1: DEPTH
112/11/9 4:20:1: DEPTH
112/11/9 4:20:1: SKELETON
112/11/9 4:20:1: SKELETON
112/11/9 4:20:1: SKELETON
112/11/9 4:20:1: SKELETON
112/11/9 4:20:1: DEPTH
112/11/9 4:20:1: SKELETON
112/11/9 4:20:1: DEPTH
112/11/9 4:20:1: SKELETON
112/11/9 4:20:1: DEPTH
112/11/9 4:20:1: SKELETON
112/11/9 4:20:1: DEPTH
112/11/9 4:20:1: SKELETON
112/11/9 4:20:2: DEPTH
112/11/9 4:20:2: SKELETON
112/11/9 4:20:2: SKELETON
112/11/9 4:20:2: SKELETON
112/11/9 4:20:2: SKELETON
112/11/9 4:20:2: SKELETON
112/11/9 4:20:2: DEPTH
112/11/9 4:20:2: DEPTH
112/11/9 4:20:2: DEPTH
112/11/9 4:20:2: DEPTH
112/11/9 4:20:2: SKELETON
112/11/9 4:20:2: SKELETON
112/11/9 4:20:2: SKELETON
112/11/9 4:20:2: SKELETON
112/11/9 4:20:2: SKELETON
112/11/9 4:20:2: SKELETON
112/11/9 4:20:2: SKELETON
112/11/9 4:20:2: SKELETON
112/11/9 4:20:2: DEPTH
112/11/9 4:20:2: SKELETON
112/11/9 4:20:2: SKELETON
112/11/9 4:20:2: DEPTH
112/11/9 4:20:2: SKELETON
112/11/9 4:20:2: SKELETON
112/11/9 4:20:2: DEPTH
112/11/9 4:20:2: SKELETON
112/11/9 4:20:2: SKELETON
112/11/9 4:20:2: SKELETON
112/11/9 4:20:2: DEPTH
112/11/9 4:20:3: DEPTH
112/11/9 4:20:3: SKELETON
112/11/9 4:20:3: SKELETON
112/11/9 4:20:3: DEPTH
112/11/9 4:20:3: DEPTH
112/11/9 4:20:3: SKELETON
112/11/9 4:20:3: DEPTH
112/11/9 4:20:3: SKELETON
112/11/9 4:20:3: DEPTH
112/11/9 4:20:3: SKELETON
112/11/9 4:20:3: SKELETON
112/11/9 4:20:3: SKELETON
112/11/9 4:20:3: SKELETON
112/11/9 4:20:3: SKELETON
112/11/9 4:20:3: SKELETON
112/11/9 4:20:3: DEPTH
112/11/9 4:20:3: DEPTH
112/11/9 4:20:3: DEPTH
112/11/9 4:20:3: SKELETON
112/11/9 4:20:3: SKELETON
112/11/9 4:20:3: DEPTH
112/11/9 4:20:3: SKELETON
112/11/9 4:20:3: DEPTH
112/11/9 4:20:4: SKELETON
112/11/9 4:20:4: DEPTH
112/11/9 4:20:4: DEPTH
112/11/9 4:20:4: SKELETON
112/11/9 4:20:4: SKELETON
112/11/9 4:20:4: DEPTH
112/11/9 4:20:4: DEPTH
112/11/9 4:20:4: DEPTH
112/11/9 4:20:4: SKELETON
112/11/9 4:20:4: SKELETON
112/11/9 4:20:4: DEPTH
112/11/9 4:20:4: DEPTH
112/11/9 4:20:4: SKELETON
112/11/9 4:20:4: SKELETON
112/11/9 4:20:4: DEPTH
112/11/9 4:20:4: DEPTH
112/11/9 4:20:4: DEPTH
112/11/9 4:20:4: SKELETON
112/11/9 4:20:4: SKELETON
112/11/9 4:20:5: DEPTH
112/11/9 4:20:5: SKELETON
112/11/9 4:20:5: DEPTH
112/11/9 4:20:5: SKELETON
112/11/9 4:20:5: SKELETON
112/11/9 4:20:5: DEPTH
112/11/9 4:20:5: DEPTH
112/11/9 4:20:5: SKELETON
112/11/9 4:20:5: DEPTH
112/11/9 4:20:5: SKELETON
112/11/9 4:20:5: DEPTH
112/11/9 4:20:5: SKELETON
112/11/9 4:20:5: SKELETON
112/11/9 4:20:5: DEPTH
112/11/9 4:20:5: SKELETON
112/11/9 4:20:5: DEPTH
112/11/9 4:20:5: SKELETON
112/11/9 4:20:5: DEPTH
112/11/9 4:20:5: SKELETON
112/11/9 4:20:5: DEPTH
112/11/9 4:20:5: DEPTH
112/11/9 4:20:5: SKELETON
112/11/9 4:20:5: SKELETON
112/11/9 4:20:5: DEPTH
112/11/9 4:20:5: DEPTH
112/11/9 4:20:6: SKELETON
112/11/9 4:20:6: DEPTH
112/11/9 4:20:6: DEPTH
112/11/9 4:20:6: SKELETON
112/11/9 4:20:6: SKELETON
112/11/9 4:20:6: DEPTH
112/11/9 4:20:6: SKELETON
112/11/9 4:20:6: SKELETON
112/11/9 4:20:6: SKELETON
112/11/9 4:20:6: SKELETON
112/11/9 4:20:6: SKELETON
112/11/9 4:20:6: DEPTH
112/11/9 4:20:6: SKELETON
112/11/9 4:20:6: DEPTH
112/11/9 4:20:6: SKELETON
112/11/9 4:20:6: SKELETON
112/11/9 4:20:6: SKELETON
112/11/9 4:20:6: SKELETON
112/11/9 4:20:6: DEPTH
112/11/9 4:20:6: SKELETON
112/11/9 4:20:6: SKELETON
112/11/9 4:20:6: SKELETON
112/11/9 4:20:6: DEPTH
112/11/9 4:20:6: DEPTH
N
112/11/9 4:20:7: SKELETON
112/11/9 4:20:7: DEPTH
112/11/9 4:20:7: DEPTH
112/11/9 4:20:7: SKELETON
112/11/9 4:20:7: SKELETON
112/11/9 4:20:7: DEPTH
112/11/9 4:20:8: SKELETON
112/11/9 4:20:8: DEPTH
112/11/9 4:20:8: SKELETON
112/11/9 4:20:8: SKELETON
112/11/9 4:20:8: DEPTH
112/11/9 4:20:8: DEPTH
112/11/9 4:20:8: SKELETON
112/11/9 4:20:8: SKELETON
112/11/9 4:20:8: SKELETON
112/11/9 4:20:8: SKELETON
112/11/9 4:20:8: DEPTH
112/11/9 4:20:8: SKELETON
112/11/9 4:20:8: SKELETON
112/11/9 4:20:8: DEPTH
112/11/9 4:20:8: DEPTH
112/11/9 4:20:8: SKELETON
112/11/9 4:20:8: DEPTH
112/11/9 4:20:8: SKELETON
112/11/9 4:20:8: SKELETON
112/11/9 4:20:8: DEPTH
112/11/9 4:20:8: DEPTH
112/11/9 4:20:8: SKELETON
112/11/9 4:20:8: SKELETON
112/11/9 4:20:8: SKELETON
112/11/9 4:20:8: DEPTH
112/11/9 4:20:8: SKELETON
112/11/9 4:20:8: SKELETON
112/11/9 4:20:8: SKELETON
112/11/9 4:20:8: DEPTH
112/11/9 4:20:8: SKELETON
112/11/9 4:20:8: SKELETON
112/11/9 4:20:8: DEPTH
112/11/9 4:20:9: SKELETON
112/11/9 4:20:9: DEPTH
112/11/9 4:20:9: SKELETON
112/11/9 4:20:9: SKELETON
112/11/9 4:20:9: DEPTH
112/11/9 4:20:9: SKELETON
112/11/9 4:20:9: DEPTH
112/11/9 4:20:9: SKELETON
112/11/9 4:20:9: DEPTH
112/11/9 4:20:9: SKELETON
112/11/9 4:20:9: DEPTH
112/11/9 4:20:9: SKELETON
112/11/9 4:20:9: SKELETON
112/11/9 4:20:9: DEPTH
112/11/9 4:20:9: SKELETON
112/11/9 4:20:9: DEPTH
112/11/9 4:20:9: DEPTH
112/11/9 4:20:9: SKELETON
112/11/9 4:20:9: SKELETON
112/11/9 4:20:9: SKELETON
112/11/9 4:20:9: DEPTH
112/11/9 4:20:9: SKELETON
112/11/9 4:20:9: SKELETON
112/11/9 4:20:9: SKELETON
112/11/9 4:20:9: DEPTH
112/11/9 4:20:9: SKELETON
112/11/9 4:20:9: SKELETON
112/11/9 4:20:9: SKELETON
112/11/9 4:20:10: DEPTH
112/11/9 4:20:10: SKELETON
112/11/9 4:20:10: SKELETON
112/11/9 4:20:10: SKELETON
112/11/9 4:20:10: DEPTH
112/11/9 4:20:10: SKELETON
112/11/9 4:20:10: SKELETON
112/11/9 4:20:10: DEPTH
112/11/9 4:20:10: SKELETON
112/11/9 4:20:10: SKELETON
112/11/9 4:20:10: SKELETON
112/11/9 4:20:10: DEPTH
112/11/9 4:20:10: SKELETON
112/11/9 4:20:10: SKELETON
112/11/9 4:20:10: DEPTH
112/11/9 4:20:10: SKELETON
112/11/9 4:20:10: SKELETON
112/11/9 4:20:10: DEPTH
112/11/9 4:20:10: SKELETON
112/11/9 4:20:10: DEPTH
112/11/9 4:20:10: SKELETON
112/11/9 4:20:10: DEPTH
112/11/9 4:20:10: SKELETON
112/11/9 4:20:10: SKELETON
112/11/9 4:20:10: DEPTH
112/11/9 4:20:10: SKELETON
112/11/9 4:20:10: DEPTH
112/11/9 4:20:10: SKELETON
112/11/9 4:20:11: SKELETON
112/11/9 4:20:11: DEPTH
112/11/9 4:20:11: SKELETON
112/11/9 4:20:11: DEPTH
112/11/9 4:20:11: SKELETON
112/11/9 4:20:11: DEPTH
112/11/9 4:20:11: SKELETON
112/11/9 4:20:11: DEPTH
112/11/9 4:20:11: SKELETON
112/11/9 4:20:11: SKELETON
112/11/9 4:20:11: DEPTH
112/11/9 4:20:11: SKELETON
112/11/9 4:20:11: DEPTH
112/11/9 4:20:11: SKELETON
112/11/9 4:20:11: DEPTH
112/11/9 4:20:11: SKELETON
112/11/9 4:20:11: SKELETON
112/11/9 4:20:11: DEPTH
112/11/9 4:20:11: SKELETON
112/11/9 4:20:11: DEPTH
112/11/9 4:20:11: SKELETON
112/11/9 4:20:11: SKELETON
112/11/9 4:20:11: DEPTH
112/11/9 4:20:11: DEPTH
112/11/9 4:20:11: SKELETON
112/11/9 4:20:11: DEPTH
N
112/11/9 4:20:12: DEPTH
112/11/9 4:20:12: SKELETON
112/11/9 4:20:12: DEPTH
112/11/9 4:20:12: SKELETON
112/11/9 4:20:12: DEPTH
112/11/9 4:20:12: SKELETON
112/11/9 4:20:12: SKELETON
112/11/9 4:20:12: DEPTH
112/11/9 4:20:12: SKELETON
112/11/9 4:20:12: DEPTH
112/11/9 4:20:12: SKELETON
112/11/9 4:20:12: DEPTH
112/11/9 4:20:12: SKELETON
112/11/9 4:20:12: DEPTH
112/11/9 4:20:12: SKELETON
112/11/9 4:20:12: DEPTH
112/11/9 4:20:12: SKELETON
112/11/9 4:20:12: DEPTH
112/11/9 4:20:12: SKELETON
112/11/9 4:20:12: SKELETON
112/11/9 4:20:12: DEPTH
112/11/9 4:20:12: DEPTH
112/11/9 4:20:12: SKELETON
112/11/9 4:20:12: SKELETON
112/11/9 4:20:12: DEPTH
112/11/9 4:20:13: SKELETON
112/11/9 4:20:13: DEPTH
112/11/9 4:20:13: SKELETON
112/11/9 4:20:13: SKELETON
112/11/9 4:20:13: DEPTH
112/11/9 4:20:13: SKELETON
112/11/9 4:20:13: DEPTH
112/11/9 4:20:13: DEPTH
112/11/9 4:20:13: SKELETON
112/11/9 4:20:13: SKELETON
112/11/9 4:20:13: SKELETON
112/11/9 4:20:13: DEPTH
112/11/9 4:20:13: SKELETON
112/11/9 4:20:13: DEPTH
112/11/9 4:20:13: SKELETON
112/11/9 4:20:13: DEPTH
112/11/9 4:20:13: SKELETON
112/11/9 4:20:13: SKELETON
112/11/9 4:20:13: DEPTH
112/11/9 4:20:13: DEPTH
112/11/9 4:20:13: DEPTH
112/11/9 4:20:13: SKELETON
112/11/9 4:20:13: DEPTH
112/11/9 4:20:13: SKELETON
112/11/9 4:20:13: SKELETON
112/11/9 4:20:13: SKELETON
112/11/9 4:20:14: SKELETON
112/11/9 4:20:14: DEPTH
112/11/9 4:20:14: SKELETON
112/11/9 4:20:14: DEPTH
112/11/9 4:20:14: SKELETON
112/11/9 4:20:14: SKELETON
112/11/9 4:20:14: DEPTH
112/11/9 4:20:14: DEPTH
112/11/9 4:20:14: SKELETON
112/11/9 4:20:14: SKELETON
112/11/9 4:20:14: DEPTH
112/11/9 4:20:14: SKELETON
112/11/9 4:20:14: SKELETON
112/11/9 4:20:14: DEPTH
112/11/9 4:20:14: SKELETON
112/11/9 4:20:14: SKELETON
112/11/9 4:20:14: DEPTH
112/11/9 4:20:14: SKELETON
112/11/9 4:20:14: DEPTH
112/11/9 4:20:14: SKELETON
112/11/9 4:20:14: DEPTH
112/11/9 4:20:14: SKELETON
112/11/9 4:20:14: SKELETON
112/11/9 4:20:14: DEPTH
112/11/9 4:20:15: SKELETON
112/11/9 4:20:15: DEPTH
112/11/9 4:20:15: SKELETON
112/11/9 4:20:15: DEPTH
112/11/9 4:20:15: SKELETON
112/11/9 4:20:15: DEPTH
112/11/9 4:20:15: DEPTH
112/11/9 4:20:15: SKELETON
112/11/9 4:20:15: SKELETON
112/11/9 4:20:15: DEPTH
【问题讨论】:
您使用什么事件来捕获数据?AllFramesReady
与个别事件相比,可以帮助您同步数字。还可以查看 CodePlex 的“Kinect Toolbox”项目;提供录音机。
谢谢,但我正在 c++ 下开发,AllFramesReady 在 c++ 中不能作为事件使用
【参考方案1】:
拥有一个由锁和条件变量保护的共享表,该变量保持对已捕获的每种类型的帧数的计数。如果任一线程发现它捕获的帧比另一个多,则让它阻塞条件变量。当任一线程完成获取帧时,它会增加其类型的计数并广播条件变量。
【讨论】:
以上是关于如何同步线程以捕获相同数量的帧?的主要内容,如果未能解决你的问题,请参考以下文章