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

Windows Discussion :

Comment modifier la valeur d'un pixel en C++ sous Visual C++ embarqué


Sujet :

Windows

  1. #1
    Candidat au Club
    Inscrit en
    Décembre 2008
    Messages
    8
    Détails du profil
    Informations forums :
    Inscription : Décembre 2008
    Messages : 8
    Points : 4
    Points
    4
    Par défaut Comment modifier la valeur d'un pixel en C++ sous Visual C++ embarqué
    Bonjour

    Je débute dans ce domaine.
    J'ai actuellement le code suivant, qui compare deux images et renvoie vrai ou faux si elles sont égales ou differentes.
    j'utilise la fonction LockBit pour accéder à la mémoire. Le problème est que j'ai j'y accède en lecture. Je voudrais y accéder en écriture en meme temps pour modifier la valeur des pixels,mais je n'y arrive pas. Auriez-vous des conseils? Peut-être devrais-je revoir le problème?

    Le but est de pouvoir modifier les pixels de pBitmapImageOld.

    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
    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
    BOOL IsMotionDetected4 (IBitmapImage* pBitmapImage, IBitmapImage *pBitmapImageOld,PBMPFMT pbmpf, DWORD dwSenstivity,int color)
    {
        int k = 0;
        int red = 0;
        int green = 0;
        int blue = 0;
        int iNoMotionDetectedThreshold = 0;
        long MoreThreshCnt=0; // reset the thresh counter
        int  TreshPerix = 18;
        float TreshPerixUnit = ((float)50/24);
        PCHAR lpByte1 = NULL;
        PCHAR lpByte2 = NULL;
        int size1 = NULL; 
        int size2 = NULL;
        int size = NULL;
        int bytesPerPixel = 3; // for 24 bits
        USHORT pixel = 0;
        HRESULT hr = S_OK;
        double dSenstivityFactor = 0.006;
    
        RECT rect = {0};
        rect.right = pbmpf->nWidth;
        rect.bottom = pbmpf->nHeight;
    
        BitmapData lockedBmpData1;
        lockedBmpData1.Reserved = 0;
        hr = pBitmapImageOld->LockBits(&rect, ImageLockModeRead, pbmpf->PixelFormat, &lockedBmpData1);
    
        BitmapData lockedBmpData2;
        lockedBmpData2.Reserved = 0;
        hr = pBitmapImage->LockBits(&rect, ImageLockModeRead, pbmpf->PixelFormat, &lockedBmpData2);
        
        ///////////////////////////////
        if (S_OK != hr)
        {
            lockedBmpData2 = lockedBmpData1;
        }
    
        double grey1 = 0, grey2 = 0;
    
        for (int y=10; y<pbmpf->nHeight-20; y=y+1)
        {
            for (int x=10; x<pbmpf->nWidth-10; x=x+2)
            {
                BYTE* pPixel = (BYTE*)lockedBmpData1.Scan0+(y*lockedBmpData1.Stride)+(x*3);
                blue = *pPixel;
                green= *(pPixel+1); 
                red = *(pPixel+2);
                grey1 = ceil(0.212671 * red + 0.715160 * green + 0.072169 * blue);
    
                
                pPixel = (BYTE*)lockedBmpData2.Scan0+(y*lockedBmpData2.Stride)+(x*3);
                
                blue = *pPixel;
                green= *(pPixel+1); 
                red = *(pPixel+2);
                grey2 = ceil(0.212671 * red + 0.715160 * green + 0.072169 * blue);
    
                if (abs((int)(grey1-grey2)) > (int)(TreshPerix))
                { 
                    // if diff between this pix in prev and cur frame > TreshPerix
                    MoreThreshCnt++; // increase motion pixels counters
                    Quand le test est vrai, Je voudrais ici pouvoir remplacer le pixel rouge par 255
    
                }
            }
        }
        
        hr = pBitmapImageOld->UnlockBits(&lockedBmpData1);
        hr = pBitmapImage->UnlockBits(&lockedBmpData2);
    
        // Set iNoMotionDetectedThreshold to number of pixels that must change 
        // in the two frames before motion is said to be detected.
        // g_iSenstivity is set by the user, 
    
        iNoMotionDetectedThreshold = (int)(dSenstivityFactor*dwSenstivity * pbmpf->nWidth * pbmpf->nHeight);
        
        //////////////////////////////////////////////////////////
        // See if motion detected
        
        if (MoreThreshCnt > iNoMotionDetectedThreshold) 
        {    
            return TRUE;
        }
    
        // No motion detected
        return FALSE;
    }
    Je vous remercie de votre aide.
    A bientot
    zouzou32300

  2. #2
    Expert éminent sénior
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Février 2005
    Messages
    5 074
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 52
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Conseil

    Informations forums :
    Inscription : Février 2005
    Messages : 5 074
    Points : 12 120
    Points
    12 120
    Par défaut
    C'est dans la doc
    : http://msdn.microsoft.com/en-us/library/ms909078.aspx
    http://msdn.microsoft.com/en-us/library/aa452244.aspx

    il suffit de remplacer :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    hr = pBitmapImageOld->LockBits(&rect, ImageLockModeRead, pbmpf->PixelFormat, &lockedBmpData1);
    
    ...
    hr = pBitmapImage->LockBits(&rect, ImageLockModeRead, pbmpf->PixelFormat, &lockedBmpData2);
    par
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    hr = pBitmapImageOld->LockBits(&rect, ImageLockModeRead | ImageLockModeWrite, pbmpf->PixelFormat, &lockedBmpData1);
    
    ...
    hr = pBitmapImage->LockBits(&rect, ImageLockModeRead | ImageLockModeWrite, pbmpf->PixelFormat, &lockedBmpData2);

  3. #3
    Candidat au Club
    Inscrit en
    Décembre 2008
    Messages
    8
    Détails du profil
    Informations forums :
    Inscription : Décembre 2008
    Messages : 8
    Points : 4
    Points
    4
    Par défaut
    Merci beaucoup pour ton aide

    a bientot
    zouzou32300

Discussions similaires

  1. [XSL] Comment modifier la valeur d'une variable?
    Par sorcer1 dans le forum XSL/XSLT/XPATH
    Réponses: 8
    Dernier message: 17/02/2010, 13h26
  2. Réponses: 8
    Dernier message: 04/04/2007, 12h22
  3. Réponses: 9
    Dernier message: 04/05/2006, 17h33
  4. Réponses: 5
    Dernier message: 21/04/2006, 14h49
  5. Réponses: 4
    Dernier message: 29/03/2006, 08h22

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