本文整理汇总了C++中cv::VideoCapture::isOpened方法的典型用法代码示例。如果您正苦于以下问题:C++ VideoCapture::isOpened方法的具体用法?C++ VideoCapture::isOpened怎么用?C++ VideoCapture::isOpened使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cv::VideoCapture
的用法示例。
在下文中一共展示了VideoCapture::isOpened方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: VideoCaptureManager
VideoCaptureManager()
: cap_(0)
{
if(!cap_.isOpened()){
std::cerr << "failed to open" << std::endl;
}
}
示例4: initVideo
///////////////////////////////////////////////////////////////////////////////
// initalize the video for processing
///////////////////////////////////////////////////////////////////////////////
void initVideo( string videoFile ){
vidCap = cv::VideoCapture( videoFile );
if( !vidCap.isOpened() ){
cout << "Video did not open" << endl;
shutItDown(-1);
}
width = vidCap.get(CV_CAP_PROP_FRAME_WIDTH);
height = vidCap.get(CV_CAP_PROP_FRAME_HEIGHT);
cout << "width: " << vidCap.get(CV_CAP_PROP_FRAME_WIDTH) << endl;
cout << "height: " << vidCap.get(CV_CAP_PROP_FRAME_HEIGHT) << endl;
currentImage = cv::Mat(640,480, CV_8UC3);
frameCount = 0;
vidCap.read(currentImage);
cv::cvtColor(currentImage, currGray, CV_BGR2GRAY);
swap(prevGray, currGray); swap(prevImage, currentImage);
flow = cv::Mat(currentImage.size(), CV_32FC2);
termcrit = cv::TermCriteria(CV_TERMCRIT_ITER|CV_TERMCRIT_EPS, 20, 0.03);
needToInit = true;
rel_vec_x = 1.0f;
rel_vec_y = 0.0f;
}
示例5: initVideoStream
void initVideoStream(cv::VideoCapture &cap)
{
if (cap.isOpened())
cap.release();
cap.open(0); // open the default camera
}
示例6: initCamera
bool Director::initCamera()
{
#if SIMULATOR == 1
if (!capture.isOpened()) {
cerr << "Error: Can not open camera!" << endl;
return false;
}
#else
fc2Error error = fc2CreateContext(&context);
if (error != FC2_ERROR_OK) {
cerr << "Error in fc2CreateContext:" << error << endl;
return false;
}
unsigned int numCameras = 0;
error = fc2GetNumOfCameras(context, &numCameras);
if (error != FC2_ERROR_OK) {
cerr << "Error in fc2GetNumOfCameras: " << error << endl;
return false;
}
if (numCameras == 0) {
// No cameras detected
cerr << "No cameras detected." << endl;
return false;
}
// Get the 0th camera
fc2PGRGuid guid;
error = fc2GetCameraFromIndex(context, 0, &guid);
if (error != FC2_ERROR_OK) {
cerr << "Error in fc2GetCameraFromIndex: " << error << endl;
return false;
}
error = fc2Connect(context, &guid);
if (error != FC2_ERROR_OK) {
cerr << "Error in fc2Connect: " << error << endl;
return false;
}
error = fc2StartCapture(context);
if (error != FC2_ERROR_OK) {
cerr << "Error in fc2StartCapture: " << error << endl;
return false;
}
error = fc2CreateImage(&rawImage);
if (error != FC2_ERROR_OK) {
cerr << "Error in fc2CreateImage: " << error << endl;
return false;
}
error = fc2CreateImage(&image);
if (error != FC2_ERROR_OK) {
cerr << "Error in fc2CreateImage: " << error << endl;
return false;
}
#endif
return true;
}
示例7: 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
{
示例8: isOpened
bool isOpened(){
if(capture_type==0){
return videoCapture.isOpened();
}else{
return imageCapture.isOpened();
}
};
示例9: getImageFromCamera
static cv::Mat getImageFromCamera() {
myLog << "get image from camera";
if(cap.isOpened() == false) {
myLog << "ERROR: can`t initialise the cam";
}
cv::Mat currentImage;
for(int i = 0; i < 6; i++) {
cap >> currentImage;
}
return currentImage;
}
示例10: 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;
}
示例11: 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;
}
示例12: 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);
}
示例13: Init
void Init(cv::VideoCapture& capture)
{
if(!capture.isOpened()){
std::cout << "error starting video capture" << std::endl;
exit(0);
}
//propose a resolution
capture.set(CV_CAP_PROP_FRAME_WIDTH, RESOLUTION_X);
capture.set(CV_CAP_PROP_FRAME_HEIGHT, RESOLUTION_Y);
//get the actual (supported) resolution
ivWidth = capture.get(CV_CAP_PROP_FRAME_WIDTH);
ivHeight = capture.get(CV_CAP_PROP_FRAME_HEIGHT);
std::cout << "camera/video resolution: " << ivWidth << "x" << ivHeight << std::endl;
cv::namedWindow("MOCTLD", 0); //CV_WINDOW_AUTOSIZE );
// cv::resizeWindow("MOCTLD", ivWidth, ivHeight);
cv::setMouseCallback("MOCTLD", MouseHandler);
}
示例14: fInitCamera
bool fInitCamera (HWND hMainWnd, int iDeviceIndex)
{
// Create a capture window to capture the output from the camera
// The capture window is not actually displayed (in this application)
/*hgCapWnd = capCreateCaptureWindow(NULL,
WS_CHILD, // window style
0, 0, 0, 0, // position and size
hMainWnd, ID_CAP);*/
if (!cam.isOpened()){
Err("Can't connect to the camera.");
return false;
}
/*if (!hgCapWnd)
{
Err("Can't open the camera display window");
return 0;
}
if (!capDriverConnect(hgCapWnd, iDeviceIndex))
{
Err("Can't connect to the camera");
return false;
}
if (!capDriverGetCaps(hgCapWnd, &gDriverCaps, sizeof(CAPDRIVERCAPS)))
{
Err("Can't get capabilities of the camera");
return false;
}
if (!capPreview(hgCapWnd, FALSE)) // turn off preview
{
Err("capPreview FALSE failed");
return false;
}
if (!capGetStatus(hgCapWnd, &gCapStatus, sizeof(CAPSTATUS)))
{
Err("Can't get status of the camera");
return false;
}
PrintCapStatus();*/
return true; // success
}
示例15: main
int main() {
if (!camera.isOpened()) return 1;
int keyCheck = 0;
resetTimer();
MouseGlove.setCenterHSV(140,161,145);
MouseGlove.setLeftHSV(96,68,118);
MouseGlove.setRightHSV(38,205,246);
MouseGlove.setScrollHSV(63,144,204);
MouseGlove.setCenterColorThreshold(45);
MouseGlove.setLeftColorThreshold(0);
MouseGlove.setRightColorThreshold(25);
MouseGlove.setScrollColorThreshold(0);
MouseGlove.setScrollAnchorYCoordinate(240);
MouseGlove.setMinArea(100);
leftClickStatus = false;
rightClickStatus = false;
while(cv::waitKey(10) != 13) {
if (!camera.read(image)) return 1;
cv::flip(image,image,1);
MouseGlove.processCenterMarker(image);
MouseGlove.processLeftMarker(image);
MouseGlove.processRightMarker(image);
MouseGlove.processScrollMarker(image);
if (getTime() > 0.3) {
coordenadasMouse = MouseGlove.getCenterMarkerCoordinates();
MouseGlove.calibrateCoordinates(coordenadasMouse);
}
if (MouseGlove.mouseDetected()) {
MouseGlove.moveMouse(coordenadasMouse);
// }
//if (MouseGlove.getLeftClickStatus() != leftClickStatus)
// toggleLeftClick();
//if (MouseGlove.getRightClickStatus() != rightClickStatus)
// toggleRightClick();
// if (MouseGlove.scrollDetected()) {
// MouseGlove.scroll(coordenadasMouse,MouseGlove.getScrollSpeed());
// }
MouseGlove.displayMouseStatus(image);
cv::imshow("Mouse",image);
}
}