IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

OpenCV Discussion :

Algorithme de correspondance de blocs


Sujet :

OpenCV

  1. #1
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Mars 2007
    Messages
    53
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2007
    Messages : 53
    Points : 37
    Points
    37
    Par défaut Algorithme de correspondance de blocs
    Je cherche à utiliser l'algorithme de block matching. J'ai cherché dans la doc d'openCv et j'ai trouvé une fonction qui permet de faire ça : cvCalcOpticalFlowBM
    voici le code que j'ai écrit:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    #include <stdio.h>
    #include <cv.h>
    #include <highgui.h>
     
    int main()
    {
        IplImage* ImTemp1=NULL;
        IplImage* source1=NULL;
        IplImage* ImTemp2=NULL;
        IplImage* source2=NULL;
        CvCapture *input_video = cvCaptureFromFile("video.avi");
        cvSetCaptureProperty(input_video, CV_CAP_PROP_POS_FRAMES,10);
        ImTemp1=cvCloneImage(cvQueryFrame(input_video));
        cvSetCaptureProperty(input_video, CV_CAP_PROP_POS_FRAMES,11);
        ImTemp2=cvCloneImage(cvQueryFrame(input_video));
        source1 = cvCreateImage(cvGetSize(ImTemp1), IPL_DEPTH_8U, 1);
        source2 = cvCreateImage(cvGetSize(ImTemp2), IPL_DEPTH_8U, 1);
        cvCvtColor(ImTemp1, source1, CV_BGR2GRAY);
        cvCvtColor(ImTemp2, source2, CV_BGR2GRAY);
     
        cvNamedWindow("Pic1", CV_WINDOW_AUTOSIZE);
        cvShowImage("Pic1", source1);
     
        cvNamedWindow("Pic2", CV_WINDOW_AUTOSIZE);
        cvShowImage("Pic2", source2);
     
     
        IplImage* velocityX=NULL;
        IplImage* velocityY=NULL;
        velocityX = cvCreateImage(cvGetSize(source1), IPL_DEPTH_32F, 1);
        velocityY = cvCreateImage(cvGetSize(source1), IPL_DEPTH_32F, 1);
     
        cvCalcOpticalFlowBM(source1, source2, cvSize(4, 4), cvSize(1, 1), cvSize(4, 4), 0, velocityX, velocityY);
     
        cvNamedWindow("Horizontal", CV_WINDOW_AUTOSIZE);
        cvShowImage("Horizontal", velocityX);
     
        cvNamedWindow("Vertical", CV_WINDOW_AUTOSIZE);
        cvShowImage("Vertical", velocityY);
     
        cvDestroyWindow("Pic1");
        cvDestroyWindow("Pic2");
        cvDestroyWindow("Horizontal");
        cvDestroyWindow("Vertical");
     
        cvReleaseImage(&ImTemp1);
        cvReleaseImage(&ImTemp2);
        cvReleaseImage(&source1);
        cvReleaseImage(&source2);
        cvReleaseImage(&velocityY);
        cvReleaseImage(&velocityX);
        cvReleaseCapture(&input_video);
        return 0;
    }
    Le code compile bien mais à l'exécution il se plante et il affiche une erreur:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    Sizes of input arguments do not match()
    in function cvCalcOpticalFlowBM C:\..\cvoptflowbm.cpp(592)
    L'erreur vient des tailles des blocs je pense.
    Avez vous une idée sur les paramètres correctes de cette fonction?
    Merci

  2. #2
    Membre actif Avatar de Vinsss84
    Profil pro
    Inscrit en
    Février 2008
    Messages
    175
    Détails du profil
    Informations personnelles :
    Localisation : France, Rhône (Rhône Alpes)

    Informations forums :
    Inscription : Février 2008
    Messages : 175
    Points : 207
    Points
    207
    Par défaut
    http://www.itl.k.u-tokyo.ac.jp/~naka...ml#ch4_optflow

    il te faut des images en paramètres et non des captures

    CalcOpticalFlowBM

    Calculates optical flow for two images by block matching method

    void cvCalcOpticalFlowBM( const CvArr* imgA, const CvArr* imgB, CvSize blockSize,
    CvSize shiftSize, CvSize maxRange, int usePrevious,
    CvArr* velx, CvArr* vely );

    imgA
    First image, 8-bit, single-channel.
    imgB
    Second image, 8-bit, single-channel.
    blockSize
    Size of basic blocks that are compared.
    shiftSize
    Block coordinate increments.
    maxRange
    Size of the scanned neighborhood in pixels around block.
    usePrevious
    Uses previous (input) velocity field.
    velx
    Horizontal component of the optical flow of
    floor((imgA->width - blockSize.width)/shiftSize.width) × floor((imgA->height - blockSize.height)/shiftSize.height) size, 32-bit floating-point, single-channel.
    vely
    Vertical component of the optical flow of the same size velx, 32-bit floating-point, single-channel.

    The function cvCalcOpticalFlowBM calculates optical flow for overlapped blocks blockSize.width×blockSize.height pixels each, thus the velocity fields are smaller than the original images. For every block in imgA the functions tries to find a similar block in imgB in some neighborhood of the original block or shifted by (velx(x0,y0),vely(x0,y0)) block as has been calculated by previous function call (if usePrevious=1)
    =>
    OpenCv Addict

  3. #3
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Mars 2007
    Messages
    53
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2007
    Messages : 53
    Points : 37
    Points
    37
    Par défaut
    C'est pas ça le probleme
    J'ai essayé avec des images et ça marche toujours pas : la même erreur

  4. #4
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Mars 2007
    Messages
    53
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2007
    Messages : 53
    Points : 37
    Points
    37
    Par défaut
    J'ai trouvé la réponse
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
     
    #include <cv.h>
    #include <highgui.h>
    #define BS 4
     
    void main() {
            IplImage *imgA = NULL, *imgB = NULL;
            IplImage *grayA = NULL, *grayB = NULL;
            IplImage *velx = NULL, *vely = NULL;
            IplImage *result = NULL;
            imgA = cvLoadImage("00.bmp", 1);
            imgB = cvLoadImage("01.bmp", 1);
            grayA = cvCreateImage(cvGetSize(imgA), IPL_DEPTH_8U, 1);
            grayB = cvCreateImage(cvGetSize(imgA), IPL_DEPTH_8U, 1);
     
            cvCvtColor(imgA, grayA, CV_BGR2GRAY);
            cvCvtColor(imgB, grayB, CV_BGR2GRAY);
     
            CvSize size = cvGetSize(imgA);
            size.width /= BS;
            size.height /= BS;
            result = cvCreateImage(size, IPL_DEPTH_8U, 1);
            for (int i=0; i<size.height; i++) {
                    for (int j=0; j<size.width; j++) {
                            cvSet(result, CV_RGB(255,255,255), NULL);
                    }
            }
            velx = cvCreateImage(size, IPL_DEPTH_32F, 1);
            vely = cvCreateImage(size, IPL_DEPTH_32F, 1);
            cvCalcOpticalFlowBM(grayB, grayA, cvSize(BS, BS), cvSize(1, 1), cvSize(1, 1), 0, velx, vely);
            cvNamedWindow("HorFlowBM", CV_WINDOW_AUTOSIZE);
            cvShowImage("HorFlowBM", velx);
            cvNamedWindow("VerFlowBM", CV_WINDOW_AUTOSIZE);
            cvShowImage("VerFlowBM", vely);
            for (i=0; i<size.height; i+=2) {
                    for (int j=0; j<size.width; j+=2) {
                            int dx = (int)cvGetReal2D(velx, i, j);
                            int dy = (int)cvGetReal2D(vely, i, j);
                            cvLine(result, cvPoint(j, i), cvPoint(j+dx, i+dy), CV_RGB(0,0,0), 1, 8, 0);
                    }
            }
            cvNamedWindow("OpticalFlow", CV_WINDOW_AUTOSIZE);
            cvShowImage("OpticalFlow", result);
            cvWaitKey(0);
    }

Discussions similaires

  1. [Algorithme] Optimiser l'espace entre des blocs
    Par bilaloch dans le forum Algorithmes et structures de données
    Réponses: 1
    Dernier message: 10/07/2014, 02h12
  2. [Débutant] algorithme representation d'une image(binaire) en blocs
    Par lucastof dans le forum Images
    Réponses: 2
    Dernier message: 15/02/2011, 21h14
  3. [Algorithme] Correspondance de points
    Par Bleys dans le forum Algorithmes et structures de données
    Réponses: 10
    Dernier message: 20/05/2010, 19h47
  4. [MySQL] recherche avec un algorithme de correspondance avec MySQL
    Par archer dans le forum PHP & Base de données
    Réponses: 6
    Dernier message: 09/02/2010, 10h10
  5. Algorithme de randomisation ... ( Hasard ...? )
    Par Anonymous dans le forum Assembleur
    Réponses: 8
    Dernier message: 06/09/2002, 14h25

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo