Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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(WidthHeight) ; 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++]);

        }
        fclose(Seq_Avi) ;
        free(tmp) ;
    }
    else
    {
    // Cette partie ne marche pas avec les AVI non compressés !!!!!
        while( Sequence.read(src)) //Relecture de tout le fichier et traitement associé
        {
            Seq_image[Nb_Images_Seq++] = src ;
            imshow("image", src);
        }
    }
}

}

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(WidthHeight) ; 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++]);

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 tout out le fichier et traitement associé
 {
 Seq_image[Nb_Images_Seq++] = src ;
  imshow("image", src);
// AfxMessageBox(_T("Image suivante"),0,0) ;
}
 }
 }

}

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; (*.avi; *.mpg) |.avi;.mpg|All |*.avi;*.mpg|All Files (.)|.||"); (*.*)|*.*||"); CFileDialog Load(TRUE, _T(".bitmap"), _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 *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(WidthHeight) *)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) ; } } } }

}