本文整理汇总了C++中cv::VideoCapture类的典型用法代码示例。如果您正苦于以下问题:C++ VideoCapture类的具体用法?C++ VideoCapture怎么用?C++ VideoCapture使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了VideoCapture类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: capture
VCrop::VCrop(cv::VideoCapture &capture, const float &x, const float &y, const float &size) : capture(&capture) {
if (!capture.isOpened()) {
std::string error_message = "Error when reading input stream";
LOG(ERROR) << error_message;
throw error_message;
}
int frame_width = capture.get(CV_CAP_PROP_FRAME_WIDTH);
int frame_height = capture.get(CV_CAP_PROP_FRAME_HEIGHT);
VLOG(2) << "Frame Width: " << frame_width;
VLOG(2) << "Frame Height: " << frame_height;
LOG_IF(FATAL, frame_width <= 0) << "Frame width is less than zero.";
LOG_IF(FATAL, frame_height <= 0) << "Frame height is less than zero.";
float diameter = sqrt(frame_width * frame_width + frame_height * frame_height);
cv::Point2i top_left(frame_width * x, frame_height * y);
cv::Size2i rect_size(diameter * size, diameter * size);
if (top_left.x + rect_size.width > frame_width || top_left.y + rect_size.height > frame_height) {
LOG(ERROR) << "Size(" << rect_size << ") to too large for given x(" << top_left.x << ") and y(" << top_left.y << ") coordinate.";
}
roi = new cv::Rect(top_left, rect_size);
VLOG(1) << "RoI: \t" << *roi;
frame_rate = capture.get(CV_CAP_PROP_FPS);
if (isnan(frame_rate) || frame_rate <= 0) {
LOG(WARNING) << "Failed to get frame rate, setting rate to 10fps.";
frame_rate = 10;
}
VLOG(1) << "Frame Rate: \t" << frame_rate;
}
示例2: initVideoStream
void initVideoStream(cv::VideoCapture &cap)
{
if (cap.isOpened())
cap.release();
cap.open(0); // open the default camera
}
示例3: readFrameIndex
cv::Mat readFrameIndex(cv::VideoCapture cap, int frameNum){
int idx = frameNum-1;
cv::Mat frame;
bool success;
cap.set ( CV_CAP_PROP_POS_FRAMES , idx );
success = cap.retrieve(frame);
return frame;
}
示例4: openVideo
static int openVideo(cv::VideoCapture &capture, std::string filename){
std::cout << "abriendo video " << filename << std::endl;
capture.open(filename);
if (!capture.isOpened()) {
std::cout << "abriendo camara " << filename << std::endl;
int id_webcam = std::atoi(filename.c_str());
capture.open(id_webcam);
}
if (!capture.isOpened()) {
// std::cout << "no puedo abrir " << filename << std::endl;
return 0;
}
return 1;
}
示例5: readParameters
bool readParameters(int argc, char** argv)
{
if (argc<4) {
usage();
return false;
}
TheInputVideo=argv[1];
/* // read input video
if (TheInputVideo=="live") TheVideoCapturer.open(0);
else TheVideoCapturer.open(argv[1]);
if (!TheVideoCapturer.isOpened())
{
cerr<<"Could not open video"<<endl;
return false;
}*/
//read from camera
if (TheInputVideo=="live") TheVideoCapturer.open(0);
else TheVideoCapturer.open(TheInputVideo);
if (!TheVideoCapturer.isOpened())
{
cerr<<"Could not open video"<<endl;
return -1;
}
// read intrinsic file
try {
CameraParams.readFromXMLFile(argv[2]);
} catch (std::exception &ex) {
cout<<ex.what()<<endl;
return false;
}
// read board file
try {
TheBoardConfig.readFromFile(argv[3]);
} catch (std::exception &ex) {
cout<<ex.what()<<endl;
return false;
}
if(argc>4) TheMarkerSize=atof(argv[4]);
else TheMarkerSize=1.;
return true;
}
示例6: VideoCaptureManager
VideoCaptureManager()
: cap_(0)
{
if(!cap_.isOpened()){
std::cerr << "failed to open" << std::endl;
}
}
示例7: fx
void fx(ForParameter for_param, cv::VideoCapture & capture_dx){
UMat *frame_dx = new UMat[farm_size];
UMat image_dx;
Mat *canvas_dx = new Mat[farm_size];
double scale_dx = 1;
CascadeClassifier *cascade_dx = new CascadeClassifier[farm_size];
for(int i = 0; i < farm_size; i ++)
cascade_dx[i].load(cascadeName);
cout << "Video dx capturing has been started ..." << endl;
bool frame_success;
int count = 0;
while(count < 220) {
for(int j = 0; j < farm_size; j ++)
frame_success = capture_dx.read(frame_dx[j]);
if (!frame_success) break;
dx(frame_dx, canvas_dx, cascade_dx, scale_dx, count);
count ++;
}
launch_todo_job();
}
示例8: openCamera
void openCamera(cv::VideoCapture& cap, int argc, const char** argv) {
cv::CommandLineParser parser(argc, argv, keys);
int camNum = parser.get<int>("1");
cap.open(camNum);
if (!cap.isOpened()) {
//help();
std::cout << "***Could not initialize capturing...***\n";
std::cout << "Current parameter's value: \n";
exit (-1);
}
cap.set(CV_CAP_PROP_FRAME_WIDTH, 160);
cap.set(CV_CAP_PROP_FRAME_HEIGHT, 120);
}
示例9: mono_handler
void mono_handler(const lcm_recv_buf_t *rbuf, const char* channel, const lcmt_stereo *msg, void *user) {
// open the frame of the video specified by the message
// check to see if the current video is the correct video file
if (current_video_number != msg->video_number) {
video_capture.release();
std::string newfile = GetMonoFilename(msg->timestamp, msg->video_number);
if (newfile.empty()) {
return;
}
std::cout << "Opening file: " << newfile << std::endl;
if (!video_capture.open(newfile)) {
std::cerr << "Failed to open file: " << newfile << std::endl;
return;
}
current_video_number = msg->video_number;
}
video_capture.set(CV_CAP_PROP_POS_FRAMES, msg->frame_number + frame_offset);
cv::Mat frame;
video_capture >> frame;
SendImageOverLcm(lcm_, image_channel, frame);
}
示例10: InitOpenCVModules
void InitOpenCVModules() //OPENCV 데이터들의 초기화
{
/*----------------------*/
//
//
//
//
/*-----------------------*/
if (Webcam_mode)
{
camera.open(Webcam_number);
if (!camera.isOpened()) //소스 영상 에러체크
{
//error in opening the video input
cerr << "Unable to open Camera Stream" << endl;
exit(EXIT_FAILURE);
}
camera >> Current_Frame; //카메라 소스에서 Current Frame으로 데이터를 넣어준다.
}
else
{
示例11: open
bool SubsExtractor::open(string file)
{
videofile = file;
bool o = cap->open(videofile);
StartFrame = 0;
EndFrame = cap->get(CV_CAP_PROP_FRAME_COUNT);
return o;
}
示例12: shutterCB
void shutterCB(int pos, void* param){
struct timeval t;
cap.set(CV_CAP_PROP_EXPOSURE,pos);
//fcount=0; // Reset frame counter, so we dont have do wait for the avg to "catch" up
std::cout << "CALLBACK !!!: pos: " << pos << "Shutter read: " << cap.get(CV_CAP_PROP_EXPOSURE) << std::endl;
}
示例13: init_opencv
bool init_opencv()
{
if (!capture.open(0)) {
std::cerr << "error: capture.open() failed..." << std::endl;
exit(-1);
}
capture.set(CV_CAP_PROP_FRAME_WIDTH, 640);
capture.set(CV_CAP_PROP_FRAME_HEIGHT, 480);
result_img.create(cv::Size(640, 480), CV_8UC3);
return true;
}
示例14: grabFunc
void* grabFunc(void* in_data)
{
while(running)
{
pthread_mutex_lock(&mutexLock);
if(camera.isOpened())
{
camera.grab();
}
pthread_mutex_unlock(&mutexLock);
}
std::cout << "Grab thread exit." << std::endl;
}
示例15: cameraInit
void cameraInit(){
/*
cv::Mat frame;
cap >> frame; // get a new frame from camera
//cvtColor(frame, edges, CV_BGR2GRAY);
//GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5);
//Canny(edges, edges, 0, 30, 3);
imshow("edges", frame);
cv::waitKey(30);
}
*/
cap.set(CV_CAP_PROP_FRAME_WIDTH,1280);
cap.set(CV_CAP_PROP_FRAME_HEIGHT,720);
cap.set(CV_CAP_PROP_FPS, 30);
}