📄 grabv4l.cc
字号:
const char *help = "\progname: grabv4l.cc\n\code2html: This program grabs images using the V4L interface.\n\version: Torch3 vision2.0, 2003-2005\n\(c) Sebastien Marcel (marcel@idiap.ch)\n";#include "VideoGrabberV4L.h"#include "ImageRgb.h"#include "MTimer.h"#include "CmdLine.h"using namespace Torch;int main(int argc, char **argv){ int device; int width; int height; int n; char *input_format; bool verbose; bool saveppm; // Construct the command line CmdLine cmd; cmd.setBOption("write log", false); // Put the help line at the beginning cmd.info(help); cmd.addText("\nArguments:"); cmd.addICmdArg("device", &device, "device"); cmd.addText("\nOptions:"); cmd.addICmdOption("-width", &width, 384, "width"); cmd.addICmdOption("-height", &height, 288, "height"); cmd.addBCmdOption("-verbose", &verbose, false, "verbose"); cmd.addBCmdOption("-ppm", &saveppm, false, "save frames as ppm"); cmd.addSCmdOption("-ifmt", &input_format, "YUV420P", "YUV420 planar"); cmd.addICmdOption("-n", &n, 10, "number of frames to gran"); cmd.read(argc, argv); ImageRgb *image = NULL; VideoGrabber *video = NULL; VirtualPixmap *currentFrame = NULL; // image = new ImageRgb(width, height); // char devname[40]; char imagename[40]; sprintf(devname, "/dev/video%d", device); int videochannel = 3; video = new VideoGrabberV4L(devname, width, height, "RGB24", input_format, -1, videochannel, 30, verbose); if(video->isOk()) { if(video->initVideoSource()) { print("Video source initialized.\n"); if(video->openVideoSource()) { print("Video source opened.\n"); MTimer timer; timer.reset(); for(int i = 0 ; i < n ; i++) { if(verbose) print(":"); currentFrame = video->getframe(); if(verbose) print("."); if(saveppm) { image->copyFrom(width, height, (unsigned char *) currentFrame->getpixmap(), "rgb"); sprintf(imagename, "frame%02d.ppm", i); image->save(imagename); } video->releaseframe(currentFrame); } timer.stop(); if(verbose) print("\n"); print(" %d frames captured in %02dh %02dm %02ds %02dms %02dus %02dns\n", n, timer.hours, timer.minutes, timer.seconds, timer.mseconds, timer.useconds, timer.nseconds); } video->closeVideoSource(); print("Video source closed.\n"); } } delete video; delete image; return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -