如何同步线程以捕获相同数量的帧?

时间:2012-12-09 02:58:30

标签: c++ multithreading synchronization kinect

我正在开发一个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

1 个答案:

答案 0 :(得分:0)

拥有一个由锁和条件变量保护的共享表,该变量保持已捕获的每种类型的帧数。如果任一线程看到它捕获的帧数多于另一个,则让它阻塞条件变量。当任一线程完成获取帧时,它会增加其类型的计数并广播条件变量。