1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <string.h>
char *lien = "c/test.avi";
void funVideo(const char* filename, int i, int tab[600][600])
{
CvCapture* capture = cvCreateFileCapture(filename);
IplImage* image;
int j;
CvScalar pixel;
if(!capture){
printf("Probleme");
return;
}
do{
cvGrabFrame(capture);
image = cvRetrieveFrame(capture);
if(image){
}
i--;
}while(image && i);
if(image){
printf("%d / %d \n",image->width,image->height);
for(i=0; i < image->width ; i++){
for(j=0; j < image->height ; j++){
pixel = cvGet2D(image,j,i);
tab[i][j] = pixel.val[0] + pixel.val[1]*1000 + pixel.val[2]*1000000;
}
}
}
}
void separation_image (const char* filename)
{
int i = 100; /* nombre d'image que l'on va augmenter (ici 100) */
int j = 1; /* compteur pour numeroter les images */
CvCapture* capture = cvCreateFileCapture(filename);
IplImage* image; /* capture de l'image depuis la video */
mkdir("images",0777); /* création du dossier + gestion des droits d'acces */
if(!capture)
{
printf("Probleme");
return;
}
do
{
char s1[100] = "images/img";
char s2[] = ".bmp";
char n[10];
cvGrabFrame(capture);
image = cvRetrieveFrame(capture);
sprintf(n, "%i", j); /* manipulation des chaines de caracteres \
*/
strcat(s1,n);
strcat(s1,s2);
cvSaveImage(s1,image); /* on l'enregistre */
j++;
i--;
}while(image && i);
}
void print_tab(int tab[600][600])
{
printf("%d\n", tab[50][69]);
printf("%d\n", tab[56][400]);
printf("%d\n", tab[267][0]);
printf("%d\n", tab[53][60]);
}
int main(void)
{
/* int tab[600][600]; */
/* funVideo(lien,5,tab); */
separation_image (lien);
return 0;
} |
Partager