Ask Your Question
2

videocapture not working with uncompressed files

asked 2012-09-06 09:05:48 -0600

Pierre gravatar image

updated 2012-10-24 04:51:59 -0600

AlexanderShishkov gravatar image

I try to read uncompressed video files, created by using videowriter and the Y800 FOURCC code and I always have a program crash. I can read the video file generated with Windows media player. The used code is the following :

void CMFC_OpencvDlg::OnBnClickedBlobSeq()
{
    static CString Filter=_T("Video files (*.avi; *.mpg) |*.avi;*.mpg|All Files (*.*)|*.*||");
    CFileDialog Load(TRUE, _T("*.bitmap"), NULL, OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST|OFN_HIDEREADONLY,Filter,NULL); 
    Load.m_ofn.lpstrTitle= _T("Lecture video");
    int value = 0 ;

    if (Load.DoModal() == IDOK) 
    {
        img_path = Load.GetPathName() ;
        VideoCapture Sequence(img_path);
        while( true) //Show the image captured in the window and repeat
        {
            Sequence >> src;
            if (src.empty() ) return ;
            imshow("image", src);
            AfxMessageBox(_T("Image"),0,0) ;
        }
    }
}

If I use an other Codec all is OK the program works perfectly, But I need work on uncompressed images in order to not degrade image quality.

I am working under Windows 7 with Microsoft Visual Studio 10.

Does some body have an idea on what happens ?

Thanks

edit retag flag offensive close merge delete

Comments

I have the same problem. Need help plz. Thanks

adahbingee gravatar imageadahbingee ( 2012-10-24 04:51:01 -0600 )edit

I too have the same problem.

Nate gravatar imageNate ( 2013-02-13 18:08:13 -0600 )edit

1 answer

Sort by » oldest newest most voted
0

answered 2012-12-14 07:01:13 -0600

Pierre gravatar image

updated 2012-12-14 07:10:50 -0600

The problem is not solved but I find a procedure to skirt this problem by reading images separately. First it is necessary to open the sequence to get the FOURCC code and information on the video file, size of images, number of images ...Then if the FOURCC corresponds to a non compressed AVI you close the sequence and re open it by classical C function fopen and jump the header, and then use the fread function to get each image. see the following code :

   void CMFC_OpencvDlg::OnBnClickedLitSeqAvi()
{
static CString Filter=_T("Video files (*.avi; *.mpg) |*.avi;*.mpg|All Files (*.*)|*.*||");
    CFileDialog Load(TRUE, _T("*.bitmap"), NULL, OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST|OFN_HIDEREADONLY,Filter,NULL); 
    Load.m_ofn.lpstrTitle= _T("Lecture video");
    int value = 0 ;
    double Height, Width, Nb_images, Code  ;
    FILE *Seq_Avi ;
    Mat Img ;
    if (Load.DoModal() == IDOK) 
    {
        img_path = Load.GetPathName() ;
        Nom_de_Sequence = Load.GetPathName() ; 
        Nom_de_Sequence.Truncate(Nom_de_Sequence.GetLength()-4) ;
        VideoCapture Sequence(img_path);
        Nb_images = Sequence.get(CV_CAP_PROP_FRAME_COUNT ) ;
        Width = Sequence.get(CV_CAP_PROP_FRAME_WIDTH ) ;
        Height = Sequence.get(CV_CAP_PROP_FRAME_HEIGHT ) ;
        Code = Sequence.get(CV_CAP_PROP_FOURCC ) ;
        Nb_Images_Seq = 0 ;
        if (Code == CV_FOURCC('Y','8','0','0')|| (Code == 0 ))
        {
            Sequence.release() ;  // Fermeture du fichier 
            char *tmp, c ;
            string Tag = "movi00d" ;
            int i =0 ;
            fpos_t pos;
            BOOLEAN Fin = TRUE ;
            tmp = (char *)malloc(Width*Height) ;
            fopen_s(&Seq_Avi,img_path.c_str(),"rb") ;
            do  // Gestion de la taille d'entête variable
            {
                fread(&c,1,1,Seq_Avi) ;
                if (c==Tag[i]) 
                {
                    i++ ;
                    if (i==7) Fin = FALSE ;
                    if (i==4)  fgetpos(Seq_Avi,&pos) ;
                }
                else i = 0 ;
            }
            while (Fin) ;
            fsetpos( Seq_Avi, &pos ) ;
            for (i= 0 ; i < Nb_images ;i++)
            {
                fread(tmp,1,8,Seq_Avi) ;  // Saut du séparateur, "00dc"+taille image
                fread(tmp,1,Width*Height,Seq_Avi) ;
                Img = Mat(Height, Width, CV_8U, tmp) ;
                Seq_image[Nb_Images_Seq] = Img.clone() ;
                if (Code == 0 ) flip(Seq_image[Nb_Images_Seq],Seq_image[Nb_Images_Seq],0 ) ;  // Lorsque le code est 0 les images sont stokées bas en haut 
                imshow("image", Seq_image[Nb_Images_Seq++]);
        //      AfxMessageBox(_T("Image suivante"),0,0) ;
            }
            fclose(Seq_Avi) ;
            free(tmp) ;
        }
        else
        {
        // Cette partie ne marche pas avec les AVI non compressés !!!!!
            while( Sequence.read(src)) //Relecture de out le fichier et traitement associé
            {
                Seq_image[Nb_Images_Seq++] = src ;
                imshow("image", src);
        //      AfxMessageBox(_T("Image suivante"),0,0) ;
            }
        }
    }
}
edit flag offensive delete link more

Comments

Hi Pierre,

Right now I am having the same problem when reading uncompressed videos. I understood the idea of your code but I would like to know something else about the do-while loop where you jump the header. First what is that string named 'tag'? Since my video does not contain this string I am getting and error when trying to read it. Thank you!

Matheus Galvez gravatar imageMatheus Galvez ( 2013-05-24 10:38:00 -0600 )edit

Question Tools

Stats

Asked: 2012-09-06 09:05:48 -0600

Seen: 1,561 times

Last updated: Dec 14 '12