使用 libfreenect 使用 kinect 捕获视频
capture video with kinect using libfreenect
我正在尝试使用 kinect 捕捉视频以用于 video/image 处理目的
我发现 libfreenect/build/bin 文件夹中有一个名为 fakenect-record 的脚本可以为我做这个
当我使用它时,它开始以 ppm 和 pgm 格式(均为图像)捕获 rgb 和深度数据,并且它还有一个选项 (-ffmpeg) 制作视频的 avi 文件,但是问题是当我它失败并说这个错误时:
Depth Mode: {256, 1, {0}, 614400, 640, 480, 11, 5, 30, 1}
Video Mode: {256, 1, {0}, 921600, 640, 480, 24, 0, 30, 1}
[Stream 70] Expected 1748 data bytes, but got 948
ffmpeg -pix_fmt rgb24 -s 640x480 -f rawvideo -i /dev/stdin -aspect 4:3 -r 20 -vcodec msmpeg4 -b 30000k sadra-depth.avi
ffmpeg -pix_fmt rgb24 -s 640x480 -f rawvideo -i /dev/stdin -aspect 4:3 -r 20 -vcodec msmpeg4 -b 30000k sadra-rgb.avi
ffmpeg version N-76045-g97be5d4ffmpeg version N-76045-g97be5d4 Copyright (c) 2000-2015 the FFmpeg developers Copyright (c) 2000-2015 the FFmpeg developers
built with gcc 4.8 (Ubuntu 4.8.4-2ubuntu1~14.04)
configuration: --extra-libs=-ldl --prefix=/opt/ffmpeg --enable-avresample --disable-debug --enable-nonfree --enable-gpl --enable-version3 --enable-libopencore-amrnb --enable-libopencore-amrwb --disable-decoder=amrnb --disable-decoder=amrwb --enable-libpulse --enable-libdcadec --enable-libfreetype --enable-libx264 --enable-libx265 --enable-libfdk-aac --enable-libvorbis --enable-libmp3lame --enable-libopus --enable-libvpx --enable-libspeex --enable-libass --enable-avisynth --enable-libsoxr --enable-libxvid --enable-libvo-aacenc --enable-libvidstab
built with gcc 4.8 (Ubuntu 4.8.4-2ubuntu1~14.04)
configuration: --extra-libs=-ldl --prefix=/opt/ffmpeg --enable-avresample --disable-debug --enable-nonfree --enable-gpl --enable-version3 --enable-libopencore-amrnb --enable-libopencore-amrwb --disable-decoder=amrnb --disable-decoder=amrwb --enable-libpulse --enable-libdcadec --enable-libfreetype --enable-libx264 --enable-libx265 --enable-libfdk-aac --enable-libvorbis --enable-libmp3lame --enable-libopus --enable-libvpx --enable-libspeex --enable-libass --enable-avisynth --enable-libsoxr --enable-libxvid --enable-libvo-aacenc --enable-libvidstab
libavutil 55. 4.100 / 55. 4.100
libavutil 55. 4.100 / 55. 4.100
libavcodec 57. 6.100 / 57. 6.100
libavcodec 57. 6.100 / 57. 6.100
libavformat 57. 4.100 / 57. 4.100
libavformat 57. 4.100 / 57. 4.100
libavdevice 57. 0.100 / 57. 0.100
libavdevice 57. 0.100 / 57. 0.100
libavfilter 6. 11.100 / 6. 11.100
libavfilter 6. 11.100 / 6. 11.100
libavresample 3. 0. 0 / 3. 0. 0
libavresample 3. 0. 0 / 3. 0. 0
libswscale 4. 0.100 / 4. 0.100
libswresample 2. 0.100 / 2. 0.100
libswscale 4. 0.100 / 4. 0.100
libpostproc 54. 0.100 / 54. 0.100
libswresample 2. 0.100 / 2. 0.100
libpostproc 54. 0.100 / 54. 0.100
Segmentation fault (core dumped)
root@thispc-sns:~/Documents/libfreenect/build/bin/Untitled Folder# Input #0, rawvideo, from '/dev/stdin':
Duration: N/A, bitrate: 184320 kb/s
Stream #0:0: Video: rawvideo (RGB[24] / 0x18424752), rgb24, 640x480, 184320 kb/s, 25 tbr, 25 tbn, 25 tbc
Please use -b:a or -b:v, -b is ambiguous
Input #0, rawvideo, from '/dev/stdin':
Duration: N/A, start: 0.000000, bitrate: 184320 kb/s
Stream #0:0: Video: rawvideo (RGB[24] / 0x18424752), rgb24, 640x480, 184320 kb/s, 25 tbr, 25 tbn, 25 tbc
Please use -b:a or -b:v, -b is ambiguous
Output #0, avi, to 'sadra-depth.avi':
Output #0, avi, to 'sadra-rgb.avi':
Metadata:
ISFT : Metadata:
ISFT : Lavf57.4.100Lavf57.4.100
Stream #0:0 Stream #0:0: Video: msmpeg4v3 (msmpeg4) (MP43 / 0x3334504D), yuv420p, 640x480 [SAR 1:1 DAR 4:3], q=2-31, 30000 kb/s: Video: msmpeg4v3 (msmpeg4) (MP43 / 0x3334504D), yuv420p, 640x480 [SAR 1:1 DAR 4:3], q=2-31, 30000 kb/s, , 20 fps, 20 fps, 20 tbn, 20 tbn, 20 tbc20 tbc
Metadata:
Metadata:
encoder : Lavc57.6.100 msmpeg4 encoder : Lavc57.6.100 msmpeg4
Stream mapping:
Stream #0:0 -> #0:0Stream mapping:
Stream #0:0 -> #0:0 (rawvideo (native) -> msmpeg4v3 (msmpeg4))
(rawvideo (native) -> msmpeg4v3 (msmpeg4))
***[rawvideo @ 0x2a31ce0] Invalid buffer size, packet size 483328 < expected frame_size 921600
Error while decoding stream #0:0: Invalid argument
frame= 0 fps=0.0 q=0.0 Lsize= 6kB time=00:00:00.00*** bitrate=N/A
video:0kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Output file is empty, nothing was encoded (check -ss / -t / -frames parameters if used)
frame= 0 fps=0.0 q=0.0 Lsize= 6kB time=00:00:00.00 bitrate=N/A
video:0kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Output file is empty, nothing was encoded (check -ss / -t / -frames parameters if used)
Conversion failed!
运行 如果您还安装了 opencv,则在您的计算机上执行以下脚本:
import freenect
import cv2
import numpy as np
from functions import *
def nothing(x):
pass
kernel = np.ones((5, 5), np.uint8)
def pretty_depth(depth):
np.clip(depth, 0, 2**10 - 1, depth)
depth >>= 2
depth = depth.astype(np.uint8)
return depth
while 1:
dst = pretty_depth(freenect.sync_get_depth()[0])#input from kinect
cv2.imshow('Video', dst)
if cv2.waitKey(1) & 0xFF == ord('b'):
break
你看到kinect的视差图了吗?
我正在尝试使用 kinect 捕捉视频以用于 video/image 处理目的 我发现 libfreenect/build/bin 文件夹中有一个名为 fakenect-record 的脚本可以为我做这个
当我使用它时,它开始以 ppm 和 pgm 格式(均为图像)捕获 rgb 和深度数据,并且它还有一个选项 (-ffmpeg) 制作视频的 avi 文件,但是问题是当我它失败并说这个错误时:
Depth Mode: {256, 1, {0}, 614400, 640, 480, 11, 5, 30, 1}
Video Mode: {256, 1, {0}, 921600, 640, 480, 24, 0, 30, 1}
[Stream 70] Expected 1748 data bytes, but got 948
ffmpeg -pix_fmt rgb24 -s 640x480 -f rawvideo -i /dev/stdin -aspect 4:3 -r 20 -vcodec msmpeg4 -b 30000k sadra-depth.avi
ffmpeg -pix_fmt rgb24 -s 640x480 -f rawvideo -i /dev/stdin -aspect 4:3 -r 20 -vcodec msmpeg4 -b 30000k sadra-rgb.avi
ffmpeg version N-76045-g97be5d4ffmpeg version N-76045-g97be5d4 Copyright (c) 2000-2015 the FFmpeg developers Copyright (c) 2000-2015 the FFmpeg developers
built with gcc 4.8 (Ubuntu 4.8.4-2ubuntu1~14.04)
configuration: --extra-libs=-ldl --prefix=/opt/ffmpeg --enable-avresample --disable-debug --enable-nonfree --enable-gpl --enable-version3 --enable-libopencore-amrnb --enable-libopencore-amrwb --disable-decoder=amrnb --disable-decoder=amrwb --enable-libpulse --enable-libdcadec --enable-libfreetype --enable-libx264 --enable-libx265 --enable-libfdk-aac --enable-libvorbis --enable-libmp3lame --enable-libopus --enable-libvpx --enable-libspeex --enable-libass --enable-avisynth --enable-libsoxr --enable-libxvid --enable-libvo-aacenc --enable-libvidstab
built with gcc 4.8 (Ubuntu 4.8.4-2ubuntu1~14.04)
configuration: --extra-libs=-ldl --prefix=/opt/ffmpeg --enable-avresample --disable-debug --enable-nonfree --enable-gpl --enable-version3 --enable-libopencore-amrnb --enable-libopencore-amrwb --disable-decoder=amrnb --disable-decoder=amrwb --enable-libpulse --enable-libdcadec --enable-libfreetype --enable-libx264 --enable-libx265 --enable-libfdk-aac --enable-libvorbis --enable-libmp3lame --enable-libopus --enable-libvpx --enable-libspeex --enable-libass --enable-avisynth --enable-libsoxr --enable-libxvid --enable-libvo-aacenc --enable-libvidstab
libavutil 55. 4.100 / 55. 4.100
libavutil 55. 4.100 / 55. 4.100
libavcodec 57. 6.100 / 57. 6.100
libavcodec 57. 6.100 / 57. 6.100
libavformat 57. 4.100 / 57. 4.100
libavformat 57. 4.100 / 57. 4.100
libavdevice 57. 0.100 / 57. 0.100
libavdevice 57. 0.100 / 57. 0.100
libavfilter 6. 11.100 / 6. 11.100
libavfilter 6. 11.100 / 6. 11.100
libavresample 3. 0. 0 / 3. 0. 0
libavresample 3. 0. 0 / 3. 0. 0
libswscale 4. 0.100 / 4. 0.100
libswresample 2. 0.100 / 2. 0.100
libswscale 4. 0.100 / 4. 0.100
libpostproc 54. 0.100 / 54. 0.100
libswresample 2. 0.100 / 2. 0.100
libpostproc 54. 0.100 / 54. 0.100
Segmentation fault (core dumped)
root@thispc-sns:~/Documents/libfreenect/build/bin/Untitled Folder# Input #0, rawvideo, from '/dev/stdin':
Duration: N/A, bitrate: 184320 kb/s
Stream #0:0: Video: rawvideo (RGB[24] / 0x18424752), rgb24, 640x480, 184320 kb/s, 25 tbr, 25 tbn, 25 tbc
Please use -b:a or -b:v, -b is ambiguous
Input #0, rawvideo, from '/dev/stdin':
Duration: N/A, start: 0.000000, bitrate: 184320 kb/s
Stream #0:0: Video: rawvideo (RGB[24] / 0x18424752), rgb24, 640x480, 184320 kb/s, 25 tbr, 25 tbn, 25 tbc
Please use -b:a or -b:v, -b is ambiguous
Output #0, avi, to 'sadra-depth.avi':
Output #0, avi, to 'sadra-rgb.avi':
Metadata:
ISFT : Metadata:
ISFT : Lavf57.4.100Lavf57.4.100
Stream #0:0 Stream #0:0: Video: msmpeg4v3 (msmpeg4) (MP43 / 0x3334504D), yuv420p, 640x480 [SAR 1:1 DAR 4:3], q=2-31, 30000 kb/s: Video: msmpeg4v3 (msmpeg4) (MP43 / 0x3334504D), yuv420p, 640x480 [SAR 1:1 DAR 4:3], q=2-31, 30000 kb/s, , 20 fps, 20 fps, 20 tbn, 20 tbn, 20 tbc20 tbc
Metadata:
Metadata:
encoder : Lavc57.6.100 msmpeg4 encoder : Lavc57.6.100 msmpeg4
Stream mapping:
Stream #0:0 -> #0:0Stream mapping:
Stream #0:0 -> #0:0 (rawvideo (native) -> msmpeg4v3 (msmpeg4))
(rawvideo (native) -> msmpeg4v3 (msmpeg4))
***[rawvideo @ 0x2a31ce0] Invalid buffer size, packet size 483328 < expected frame_size 921600
Error while decoding stream #0:0: Invalid argument
frame= 0 fps=0.0 q=0.0 Lsize= 6kB time=00:00:00.00*** bitrate=N/A
video:0kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Output file is empty, nothing was encoded (check -ss / -t / -frames parameters if used)
frame= 0 fps=0.0 q=0.0 Lsize= 6kB time=00:00:00.00 bitrate=N/A
video:0kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Output file is empty, nothing was encoded (check -ss / -t / -frames parameters if used)
Conversion failed!
运行 如果您还安装了 opencv,则在您的计算机上执行以下脚本:
import freenect
import cv2
import numpy as np
from functions import *
def nothing(x):
pass
kernel = np.ones((5, 5), np.uint8)
def pretty_depth(depth):
np.clip(depth, 0, 2**10 - 1, depth)
depth >>= 2
depth = depth.astype(np.uint8)
return depth
while 1:
dst = pretty_depth(freenect.sync_get_depth()[0])#input from kinect
cv2.imshow('Video', dst)
if cv2.waitKey(1) & 0xFF == ord('b'):
break
你看到kinect的视差图了吗?