本文整理汇总了C++中cvCreateFileCapture函数的典型用法代码示例。如果您正苦于以下问题:C++ cvCreateFileCapture函数的具体用法?C++ cvCreateFileCapture怎么用?C++ cvCreateFileCapture使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cvCreateFileCapture函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: initCaptureFiles
// need to return positive or negative
void initCaptureFiles( int argc, char *argv[], CvCapture **capture, CvCapture **stereoCapture, int *webcamRun, int *enable3D ) {
if( argc < 3 ) {;
printf("Incorrect arguments:\n");
printf("Webcam: mainTracker mean.xml cov.xml\n");
printf("2D video: mainTracker mean.xml cov.xml video.avi");
printf("3D video: mainTracker mean.xml cov.xml video.avi stereo.avi\n");
exit(1);
}
char locationVideoActual[300];
char locationVideoStereo[300];
if( argc == 3 ) {
printf("Running on webcam\n");
*webcamRun = 1;
} else if( argc == 4 ) {
strncpy( locationVideoActual, argv[3], 300 );
} else if( argc == 5 ) {
strncpy( locationVideoActual, argv[3], 300 );
strncpy( locationVideoStereo, argv[4], 300 );
} else {
printf("Incorrect arguments:\n");
printf("Webcam: mainTracker mean.xml cov.xml\n");
printf("2D video: mainTracker mean.xml cov.xml video.avi");
printf("3D video: mainTracker mean.xml cov.xml video.avi stereo.avi\n");
exit(1);
}
if( *webcamRun ) {
*capture = cvCaptureFromCAM(0);
*stereoCapture = cvCreateFileCapture( "nonexistantfile.avi" );
} else {
*capture = cvCreateFileCapture( locationVideoActual );
*stereoCapture = cvCreateFileCapture( locationVideoStereo );
}
if ( !*capture ) {
fprintf( stderr, "Cannot open regular video file\n" );
exit(1);
} else {
fprintf( stderr, "\nRegular video loaded ok\n" );
}
if ( *stereoCapture ) {
printf("Depth file found, enabling 3D tracking\n");
*enable3D = 1;
} else {
fprintf( stderr, "Could not open depth file, using 2D tracking" );
*enable3D = 0;
}
}
示例2: test
void test() {
CvCapture *capture = cvCreateFileCapture("D:\\²âÊÔÊÓƵ\\1344.avi");
int frameWidth = cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH);
int frameHeight = cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT);
codeBook *cb = new codeBook[frameWidth * frameHeight];
memset(cb, 0, frameWidth * frameHeight * sizeof(codeBook));
unsigned int bound[3] = { 10 ,10,10 };
int minMod[3] = { 10 ,10,10 };
int maxMod[3] = { 10 ,10,10 };
IplImage *frame[1000];
for (int i = 0; i < 1000; i++) {
frame[i] = cvCreateImage(cvSize(frameWidth, frameHeight), 8, 3);
cvCopy(cvQueryFrame(capture), frame[i]);
}
for (int i = 0; i < frameWidth * frameHeight; i++) {
for (int j = 0; j < 1000; j++) {
UpdateCodeBook((unsigned char*)frame[j]->imageData + i * 3, cb[i], bound, 3);
}
}
IplImage *mask = cvCreateImage(cvSize(frameWidth, frameHeight), 8, 1);
for (int i = 0; i < 1000; i++) {
for (int j = 0; j < frameWidth * frameHeight; j++) {
mask->imageData[j] = BackgroundDiff((unsigned char*)frame[i]->imageData + j * 3, cb[j], 3, minMod, maxMod);
}
FindConnectedComponents(mask);
cvShowImage("1", mask);
cvShowImage("2", frame[i]);
cvWaitKey(30);
}
}
示例3: initVideoCapture
//Initialize capture from avi
int initVideoCapture(char* video_path)
{
capture = cvCreateFileCapture(video_path);
frames = (int) cvGetCaptureProperty(
capture,
CV_CAP_PROP_FRAME_COUNT
);
// writer = cvCreateVideoWriter(
// "my_video.avi",
// CV_FOURCC('P','I','M','1'),
// 30,
// size,
// isColor
// );
printf("no of frames = %d", frames);
if( !frames )
{
fprintf(stderr, "failed to initialize camera capture\n");
return 0;
}
return 1;
}
示例4: cvCreateFileCapture
//--------------------------------------------------------------------------------------
// Name: CVInit()
// Desc: Initializate OpenCV
//--------------------------------------------------------------------------------------
bool GLCVUtils::CVInit (int mode)
{
if (mode == VIDEO_FILE)
{
capture = cvCreateFileCapture ("Ratatouille.avi");
if (! capture) printf ("\n\n\nerror creating file capture\n\n\n");
}
else if (mode == CAMERA)
{
// create capture
capture = cvCreateCameraCapture (0);
if (! capture)
{
printf ("\nError creating capture");
return false;
}
// sets camera (hardware) resolution
cvSetCaptureProperty (capture, CV_CAP_PROP_FRAME_WIDTH, TEXTURE_W);
cvSetCaptureProperty (capture, CV_CAP_PROP_FRAME_HEIGHT, TEXTURE_H);
}
else
{
printf ("\nWrong Mode");
}
return true;
}
示例5: main
int main(int argc, char* argv[]) {
const char* filename = "./test.avi";
if(argc > 1) {
filename = argv[1];
}
CvCapture* cap = cvCreateFileCapture(filename);
if(cap == NULL) {
printf("open camera failed!\n");
return -1;
}
cvSaveImage("video.jpg", cvQueryFrame(cap));
const char* winName = "Go-OpenCV";
cvNamedWindow(winName, 1);
for(;;) {
IplImage* img = cvQueryFrame(cap);
cvShowImage(winName, img);
if(cvWaitKey(50) == 27) {
break;
}
}
cvDestroyWindow(winName);
cvReleaseCapture(&cap);
return 0;
}
示例6: readVideoWithATrackbar
int readVideoWithATrackbar(char *fileName)
{
cvNamedWindow( "win_1", CV_WINDOW_AUTOSIZE );
g_capture = cvCreateFileCapture( fileName );
int frames = (int) cvGetCaptureProperty(
g_capture,
CV_CAP_PROP_FRAME_COUNT
);
if( frames != 0 ) {
cvCreateTrackbar(
"Position",
"win_1",
&g_slider_position,
frames,
onTrackbarSlide
);
}
IplImage* frame;
while (1) {
frame = cvQueryFrame( g_capture );
if ( !frame ) {
break;
}
cvShowImage( "win_1", frame );
char c = cvWaitKey(33);
if ( c == 27 ) {
break;
}
}
return (0);
}
示例7: main
int main(int argc, const char * argv[]) {
CvCapture* capture = cvCreateFileCapture( argv[1] );
if (!capture) return -1;
IplImage* bgr_frame = cvQueryFrame( capture );
double fps = cvGetCaptureProperty( capture , CV_CAP_PROP_FPS );
CvSize size = cvSize(
(int)cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH),
(int)cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT)
);
CvVideoWriter* writer = cvCreateVideoWriter( argv[2], CV_FOURCC('M', 'J', 'P', 'G'), fps, size);
IplImage* logpolar_frame = cvCreateImage(size, IPL_DEPTH_8U, 3);
while ( (bgr_frame = cvQueryFrame(capture)) != NULL ) {
cvLogPolar(bgr_frame, logpolar_frame,
cvPoint2D32f(bgr_frame->width/2, bgr_frame->height/2),
40,
CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS );
cvWriteFrame(writer, logpolar_frame);
}
cvReleaseVideoWriter( &writer );
cvReleaseImage( &logpolar_frame );
cvReleaseCapture( &capture );
return 0;
}
示例8: main
int main(int argc, char * const argv[])
{
/* Initialize the camera */
CvCapture *CamCapture = 0;
CamCapture = cvCreateFileCapture("http://192.168.2.135:81/videostream.asf?user=viki&pwd=viki&resolution=640*480");
if (!CamCapture)
{printf("IP Cam not ready\n");
return -1;}
/* initialize video writer */
CvVideoWriter *IPCamWriter = 0;
CvSize size;
size.width = 640;
size.height = 480;
IPCamWriter = cvCreateVideoWriter("/home/viki/Videos/IPCamOut.avi", CV_FOURCC('D','I','V','X'), 4, size, 1); //needs time index in naming
/* time */
time_t current_time;
current_time = time (NULL);
long int stop_time = current_time + 10;
/* main loop */
while( current_time < stop_time )
{
/* write image to file */
cvWriteFrame(IPCamWriter, cvQueryFrame( CamCapture ));
}
/* Clean up memory */
cvReleaseCapture ( &CamCapture );
cvReleaseVideoWriter(&IPCamWriter);
}
示例9: capture_frame
VideoCapture::VideoCapture(std::string _path_to_video,
int32_t _snapshot_delay)
: capture_frame(nullptr), frame(nullptr), path_to_video(_path_to_video), snapshot_delay(_snapshot_delay), window_name("Capture"), btv_sr(nullptr)
{
capture_frame = cvCreateFileCapture(path_to_video.c_str());
btv_sr = new NS_SuperResolution::SuperResolution();
}
示例10: main
int main( int argc, char** argv ) {
if (argc == 1) {
std::cout << "ERROR: missing filename" << std::endl;
return -1;
}
cvNamedWindow( "Video Capture", CV_WINDOW_AUTOSIZE );
//CvCapture* capture = cvCaptureFromAVI( argv[1] ); // either one will work
CvCapture* capture = cvCreateFileCapture( argv[1] );
if (capture == NULL) {
std::cout << "ERROR: can not open file " << argv[1] << std::endl;
return -1;
}
IplImage* frame;
while(1) {
frame = cvQueryFrame( capture );
if( !frame ) break;
cvShowImage( "Video Capture", frame );
char c = cvWaitKey(33);
if( c == 27 ) break;
}
cvReleaseCapture( &capture );
cvDestroyWindow( "Video Capture" );
}
示例11: main
int main( int argc, char** argv ) {
cvNamedWindow( "Example3", CV_WINDOW_AUTOSIZE );
g_capture = cvCreateFileCapture( argv [1] );
int frames = (int) cvGetCaptureProperty(
g_capture,
CV_CAP_PROP_FRAME_COUNT
);
if( frames!= 0 ) {
cvCreateTrackbar(
"Position",
"Example3",
&g_slider_position,
frames,
onTrackbarSlide
);
}
IplImage* frame;
while(1) {
frame = cvQueryFrame( g_capture );
if( !frame ) break;
cvShowImage( "Example3", frame );
char c = cvWaitKey(33);
if( c == 27 ) break;
}
cvReleaseCapture( &g_capture );
cvDestroyWindow( "Example3" );
return(0);
}
示例12: main
int main(int argc, char** argv){
// Example2という名前のウィンドウを作成する
cvNamedWindow("Example2", CV_WINDOW_AUTOSIZE);
// ビデオファイルからフレームを扱えるように準備する
CvCapture *capture = cvCreateFileCapture(argv[1]);
IplImage *frame;
// ビデオファイルをループして表示する
while(1){
// ビデオファイルからフレームを読み出す
frame = cvQueryFrame(capture);
if(!frame){
break;
}
// Example2のウィンドウにフレームを表示する
cvShowImage("Example2", frame);
// 33ミリ秒キー入力を待つ
char c = cvWaitKey(33);
// エスケープキーが押されればループを抜ける
if(c == 27){
break;
}
}
// CvCapture変数を解放する
cvReleaseCapture(&capture);
// ウィンドウを閉じる
cvDestroyWindow("Example2");
return 0;
}
示例13: GetConfigurationString
void THISCLASS::OnStart() {
// Open file
wxString filename_string = GetConfigurationString(wxT("File"), wxT(""));
wxFileName filename = mCore->GetProjectFileName(filename_string);
if (! filename.FileExists()) {
wxString msg = wxT("The avi file does not exist: ");
msg << filename_string;
AddError(msg);
return;
}
if (filename.IsOk()) {
mCapture = cvCreateFileCapture(filename.GetFullPath().mb_str(wxConvFile));
}
// Error? Check whether the file exists or not, to give an appropriate error message to the user
if (mCapture == NULL) {
std::fstream f;
f.open(filename.GetFullPath().mb_str(wxConvFile));
if (f.is_open()) {
f.close();
AddError(wxT("Can open the AVI file as a file, but not with OpenCV."));
return;
} else {
AddError(wxT("Cannot open AVI file: permissions problem or something?"));
return;
}
}
// Reset to first frame
cvSetCaptureProperty(mCapture, CV_CAP_PROP_POS_FRAMES, 0);
}
示例14: cvNamedWindow
void Kalman_Filter::video_extraction()
{
cvNamedWindow( "video", CV_WINDOW_AUTOSIZE );
CvCapture* capture = cvCreateFileCapture( "fi-br-m1.avi" );
IplImage* frame;
int frameNo = 0;
while(1)
{
frame = cvQueryFrame( capture );
if (frameNo == 0) cvSaveImage("model.png", frame, 0);
if (frameNo == 30) cvSaveImage("data.png", frame, 0);
if( !frame ) break;
cvShowImage( "video", frame );
char c = cvWaitKey(33);
if( c == 27 ) break;
frameNo++;
}
cvReleaseCapture( &capture );
cvDestroyWindow( "video" );
}
示例15: main
int main(int argc, char** argv) {
CvCapture* capture = 0;
IplImage* input = 0;
IplImage* output = 0;
int tick = 0, prev_tick = 0;
double now = 0.0;
CvFont font;
char buffer[256];
const char* windowName = "median";
if (argc == 1 || (argc == 2 && strlen(argv[1]) == 1 && isdigit(argv[1][0]))) {
capture = cvCreateCameraCapture(argc == 2 ? argv[1][0] - '0' : 0);
} else if (argc == 2) {
capture = cvCreateFileCapture(argv[1]);
}
if (!capture) {
fprintf(stderr, "ERROR: capture is NULL \n");
return (-1);
}
cvNamedWindow(windowName, CV_WINDOW_AUTOSIZE);
cvInitFont(&font, CV_FONT_HERSHEY_SIMPLEX, 1.0, 1.0, 0.0, 1, 0);
input = cvQueryFrame(capture);
if (!input) {
fprintf(stderr, "Could not query frame...\n");
return (-1);
}
output = cvCreateImage(cvSize(input->width, input->height), IPL_DEPTH_8U, 3);
while (1) {
input = cvQueryFrame(capture);
if (!input) {
fprintf(stderr, "Could not query frame...\n");
break;
}
process(input, output);
sprintf(buffer, "%3.1lfms", now / 1000);
cvPutText(output, buffer, cvPoint(50, 150), &font, CV_RGB(255, 0, 0));
cvShowImage(windowName, output);
//If a certain key pressed
if (cvWaitKey(10) >= 0) {
break;
}
tick = cvGetTickCount();
now = (tick - prev_tick) / cvGetTickFrequency();
prev_tick = tick;
}
cvReleaseImage(&output);
cvReleaseCapture(&capture);
cvDestroyWindow(windowName);
return 0;
}