Précédent   Forum des professionnels en informatique > C et C++ > Bibliothèques > OpenCV
OpenCV Vos questions sur l'API de traitement d'images OpenCV.
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 25/01/2012, 13h47   #1
Invité de passage
 
Inscription : janvier 2012
Messages : 31
Détails du profil
Informations forums :
Inscription : janvier 2012
Messages : 31
Points : 0
Points : 0
Par défaut segmentation des images

bonjour, je vais implémenter le code cvwatershed d'opencv pour segmenter des images. j'ai essayé le code cvwatershed.cpp mais je dois intervenir après l'exécution. comment je dois procéder?
mathphy est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 25/01/2012, 17h18   #2
Membre régulier
 
Avatar de GabrielD
 
Homme Gabriel
ingénieur de recherche
Inscription : août 2009
Messages : 50
Détails du profil
Informations personnelles :
Nom : Homme Gabriel
Localisation : France

Informations professionnelles :
Activité : ingénieur de recherche

Informations forums :
Inscription : août 2009
Messages : 50
Points : 75
Points : 75
Peux tu préciser ta question?
Les exemples OpenCV sont fait pour expliquer comment intégrer les fonctions dans ton code.
GabrielD est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 25/01/2012, 18h39   #3
Invité de passage
 
Inscription : janvier 2012
Messages : 31
Détails du profil
Informations forums :
Inscription : janvier 2012
Messages : 31
Points : 0
Points : 0
j'ai le code suivant "watershed.cpp" qui fait la segmentation d'une image en faisant appel à la méthode cvwatershed. le pb qui m'a rencontré c'est le fait d'intervenir pour déplacer la souris sur l'image pour faire la segmentation or j'ai besoin de faire appel à cette méthode pour faire une segmentation d'une image sans aucune intervention. voici le code
#ifdef _CH_
#pragma package <opencv>
#endif

#ifndef _EiC
#include "cv.h"
#include "highgui.h"
#include <stdio.h>
#include <stdlib.h>
#endif

IplImage* marker_mask = 0;
IplImage* markers = 0;
IplImage* img0 = 0, *img = 0, *img_gray = 0, *wshed = 0;
CvPoint prev_pt = {-1,-1};

void on_mouse( int event, int x, int y, int flags, void* param )
{
if( !img )
return;

if( event == CV_EVENT_LBUTTONUP || !(flags & CV_EVENT_FLAG_LBUTTON) )
prev_pt = cvPoint(-1,-1);
else if( event == CV_EVENT_LBUTTONDOWN )
prev_pt = cvPoint(x,y);
else if( event == CV_EVENT_MOUSEMOVE && (flags & CV_EVENT_FLAG_LBUTTON) )
{
CvPoint pt = cvPoint(x,y);
if( prev_pt.x < 0 )
prev_pt = pt;
cvLine( marker_mask, prev_pt, pt, cvScalarAll(255), 5, 8, 0 );
cvLine( img, prev_pt, pt, cvScalarAll(255), 5, 8, 0 );
prev_pt = pt;
cvShowImage( "image", img );
}
}


int main( int argc, char** argv )
{
char* filename = argc >= 2 ? argv[1] : (char*)"fruits.jpg";
CvRNG rng = cvRNG(-1);

if( (img0 = cvLoadImage(filename,1)) == 0 )
return 0;

printf( "Hot keys: \n"
"\tESC - quit the program\n"
"\tr - restore the original image\n"
"\tw or SPACE - run watershed algorithm\n"
"\t\t(before running it, roughly mark the areas on the image)\n"
"\t (before that, roughly outline several markers on the image)\n" );

cvNamedWindow( "image", 1 );
cvNamedWindow( "watershed transform", 1 );

img = cvCloneImage( img0 );
img_gray = cvCloneImage( img0 );
wshed = cvCloneImage( img0 );
marker_mask = cvCreateImage( cvGetSize(img), 8, 1 );
markers = cvCreateImage( cvGetSize(img), IPL_DEPTH_32S, 1 );
cvCvtColor( img, marker_mask, CV_BGR2GRAY );
cvCvtColor( marker_mask, img_gray, CV_GRAY2BGR );

cvZero( marker_mask );
cvZero( wshed );
cvShowImage( "image", img );
cvShowImage( "watershed transform", wshed );
cvSetMouseCallback( "image", on_mouse, 0 );

for(;
{
int c = cvWaitKey(0);

if( (char)c == 27 )
break;

if( (char)c == 'r' )
{
cvZero( marker_mask );
cvCopy( img0, img );
cvShowImage( "image", img );
}

if( (char)c == 'w' || (char)c == ' ' )
{
CvMemStorage* storage = cvCreateMemStorage(0);
CvSeq* contours = 0;
CvMat* color_tab;
int i, j, comp_count = 0;
//cvSaveImage( "wshed_mask.png", marker_mask );
//marker_mask = cvLoadImage( "wshed_mask.png", 0 );
cvFindContours( marker_mask, storage, &contours, sizeof(CvContour),
CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE );
cvZero( markers );
for( ; contours != 0; contours = contours->h_next, comp_count++ )
{
cvDrawContours( markers, contours, cvScalarAll(comp_count+1),
cvScalarAll(comp_count+1), -1, -1, 8, cvPoint(0,0) );
}

color_tab = cvCreateMat( 1, comp_count, CV_8UC3 );
for( i = 0; i < comp_count; i++ )
{
uchar* ptr = color_tab->data.ptr + i*3;
ptr[0] = (uchar)(cvRandInt(&rng)%180 + 50);
ptr[1] = (uchar)(cvRandInt(&rng)%180 + 50);
ptr[2] = (uchar)(cvRandInt(&rng)%180 + 50);
}

{
double t = (double)cvGetTickCount();
cvWatershed( img0, markers );
t = (double)cvGetTickCount() - t;
printf( "exec time = %gms\n", t/(cvGetTickFrequency()*1000.) );
}

// paint the watershed image
for( i = 0; i < markers->height; i++ )
for( j = 0; j < markers->width; j++ )
{
int idx = CV_IMAGE_ELEM( markers, int, i, j );
uchar* dst = &CV_IMAGE_ELEM( wshed, uchar, i, j*3 );
if( idx == -1 )
dst[0] = dst[1] = dst[2] = (uchar)255;
else if( idx <= 0 || idx > comp_count )
dst[0] = dst[1] = dst[2] = (uchar)0; // should not get here
else
{
uchar* ptr = color_tab->data.ptr + (idx-1)*3;
dst[0] = ptr[0]; dst[1] = ptr[1]; dst[2] = ptr[2];
}
}

cvAddWeighted( wshed, 0.5, img_gray, 0.5, 0, wshed );
cvShowImage( "watershed transform", wshed );
cvReleaseMemStorage( &storage );
cvReleaseMat( &color_tab );
}
}

return 1;
}

#ifdef _EiC
main(1,"watershed.cpp");
#endif
mathphy est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 26/01/2012, 10h32   #4
Membre régulier
 
Avatar de GabrielD
 
Homme Gabriel
ingénieur de recherche
Inscription : août 2009
Messages : 50
Détails du profil
Informations personnelles :
Nom : Homme Gabriel
Localisation : France

Informations professionnelles :
Activité : ingénieur de recherche

Informations forums :
Inscription : août 2009
Messages : 50
Points : 75
Points : 75
as tu compris ce code?
Il applique deux fonctions: findcontours et watershed. Essaie d'abord de jouer avec celles-ci en utilisant le manuel OpenCV très complet et tiens nous au courant.
GabrielD est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 26/01/2012, 20h17   #5
Invité de passage
 
Inscription : janvier 2012
Messages : 31
Détails du profil
Informations forums :
Inscription : janvier 2012
Messages : 31
Points : 0
Points : 0
oui j'ai compris ce code. le pb que j'ai pas besoin de la fonction en mouse et d'utiliser le clavier pour faire des traitements je veux juste faire entrer une image et la sortie est une image segmentée mais j'arrive pas à modifier ce code .
mathphy est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 27/01/2012, 11h46   #6
Membre éprouvé
 
Homme
Chercheur en informatique
Inscription : avril 2008
Messages : 272
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : Royaume-Uni

Informations professionnelles :
Activité : Chercheur en informatique

Informations forums :
Inscription : avril 2008
Messages : 272
Points : 451
Points : 451
Ça doit bien faire la 6eme fois que tu poses cette question sur ce forum... Si la fonction d'OpenCV t'obliges a donner des coordonnées, c'est qu'il y a une raison. Si ça te convient pas, il est peut être temps de se demander si c'est vraiment cet algo que tu veux plutôt que de t'obstiner.
math_lab est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 27/01/2012, 14h02   #7
Invité de passage
 
Inscription : janvier 2012
Messages : 31
Détails du profil
Informations forums :
Inscription : janvier 2012
Messages : 31
Points : 0
Points : 0
en fait c'est un choix personnel d'utiliser cet algorithme mais le prof m'a obligé de l'utiliser pour la segmentation
mathphy est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 27/01/2012, 14h12   #8
Membre éprouvé
 
Homme
Chercheur en informatique
Inscription : avril 2008
Messages : 272
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : Royaume-Uni

Informations professionnelles :
Activité : Chercheur en informatique

Informations forums :
Inscription : avril 2008
Messages : 272
Points : 451
Points : 451
Bah alors il va peut etre falloir retrousser les manches et l'implementer soi meme.
Cours watershed sur dvp
math_lab est déconnecté   Envoyer un message privé Réponse avec citation 10
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 00h07.


 
 
 
 
Partenaires

Hébergement Web