Ask Your Question

Pierre's profile - activity

2012-12-14 07:10:05 -0600 received badge  Editor (source)
2012-12-14 07:01:13 -0600 answered a question videocapture not working with uncompressed files

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) ;
            }
        }
    }
}
2012-11-23 02:02:14 -0600 commented question VideoWriter VideoCapture and uncompressed AVI

Same problem but no solution, for me it should be a bug.

2012-09-07 08:08:59 -0600 received badge  Supporter (source)
2012-09-06 23:46:43 -0600 received badge  Student (source)
2012-09-06 09:05:48 -0600 asked a question videocapture not working with uncompressed files

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