Accueil > > > OBJECTMARKER
OBJECTMARKER
Information sur la source
Description
Code en C++ permettant avec la Bibliotheque OpenCV de "marquer" des regions d'interets dans des images, notamment pour la realisation de Machine Learning. Le code source original n'est pas de moi, j'ai cependant realiser des modifications afin de rendre le programme plus efficient, et compatible pour les utilisateurs travaillant avec Windows.
Source
- /***************objectmarker.cpp******************
-
- Objectmarker for marking the objects to be detected from positive samples and then creating the
- description file for positive images.
-
- compile this code and run with two arguments, first one the name of the descriptor file and the second one
- the address of the directory in which the positive images are located
-
- while running this code, each image in the given directory will open up. Now mark the edges of the object using the mouse buttons
- then press then press "SPACE" to save the selected region, or any other key to discard it. Then use "b" to move to next image. the program automatically
- quits at the end. press ESC at anytime to quit.
-
-
- author: achu_wilson@rediffmail.com
- author: provost.kevin@gmail.com
- */
-
- #include <opencv/cv.h>
- #include <opencv/cvaux.h>
- #include <opencv/highgui.h>
-
- // for filelisting
- #include <stdio.h>
- #include <io.h>
- // for fileoutput
- #include <string>
- #include <fstream>
- #include <sstream>
- #include <dirent.h>
- #include <sys/types.h>
-
- using namespace std;
-
- IplImage* image=0;
- IplImage* image2=0;
- int roi_x0=0;
- int roi_y0=0;
- int roi_x;
- int roi_x1=0;
- int roi_y1=0;
- int roi_y;
- int numOfRec=0;
- int startDraw = 0;
- char* window_name="<SPACE>add <b>save and load next <ESC>exit";
-
- string IntToString(int num)
- {
- ostringstream myStream; //creates an ostringstream object
- myStream << num << flush;
- return(myStream.str()); //returns the string form of the stringstream object
- };
-
- void on_mouse(int event,int x,int y,int flag, void *param)
- {
- if(event==CV_EVENT_LBUTTONDOWN)
- {
- if(!startDraw)
- {
- roi_x0=x;
- roi_y0=y;
- startDraw = 1;
- } else {
- roi_x1=x;
- roi_y1=y;
- startDraw = 0;
- }
- }
- if(event==CV_EVENT_MOUSEMOVE && startDraw)
- {
- //redraw ROI selection
- image2=cvCloneImage(image);
- cvRectangle(image2,cvPoint(roi_x0,roi_y0),cvPoint(x,y),CV_RGB(255,0,255),5);
- cvShowImage(window_name,image2);
- cvReleaseImage(&image2);
- }
- }
-
- int main(int argc, char** argv)
- {
- char iKey=0;
- string strPrefix;
- string strPostfix;
- string input_directory;
- string output_file;
-
- if(argc != 1)
- {
- fprintf(stderr, "%s output_info.txt raw/data/directory/\n", argv[0]);
- return -1;
- }
-
- input_directory = argv[2];
- output_file = argv[1];
-
- /* Get a file listing of all files with in the input directory */
- DIR *dir_p = opendir (input_directory.c_str());
- struct dirent *dir_entry_p;
-
- if(dir_p == NULL)
- {
- fprintf(stderr, "Failed to open directory %s\n", input_directory.c_str());
- return -1;
- }
-
- fprintf(stderr, "Object Marker: Input Directory: %s Output File: %s\n", input_directory.c_str(), output_file.c_str());
-
- // init highgui
- cvAddSearchPath(input_directory);
- cvNamedWindow(window_name,CV_WINDOW_KEEPRATIO);
- cvSetMouseCallback(window_name,on_mouse, NULL);
-
- fprintf(stderr, "Opening directory...");
-
- // init output of rectangles to the info file
- ofstream output(output_file.c_str());
- fprintf(stderr, "done.\n");
-
- while((dir_entry_p = readdir(dir_p)) != NULL)
- {
- numOfRec=0;
-
- if(strcmp(dir_entry_p->d_name, ""))
- fprintf(stderr, "Examining file %s\n", dir_entry_p->d_name);
- strPostfix="";
- strPrefix=input_directory;
- fprintf(stderr, "Nom repertoire 1 %s\n", strPrefix.c_str());
- strPrefix+=dir_entry_p->d_name;
- fprintf(stderr, "Nom repertoire 2 %s\n", strPrefix.c_str());
- fprintf(stderr, "Loading image %s\n", strPrefix.c_str());
-
- image=cvLoadImage(strPrefix.c_str(),1);
- printf("Valeure image %i \n", image);
-
- //Work on current image
- if(image != 0)
- {
- do
- {
- cvShowImage(window_name,image);
-
- // used cvWaitKey returns:
- // <b> save added rectangles and show next image
- // <ESC>=27 exit program
- // <Space>=32 add rectangle to current image
- iKey=cvWaitKey(0);
-
- switch(iKey)
- {
- case 27:
- cvReleaseImage(&image);
- cvDestroyWindow(window_name);
- return 0;
-
- case 32:
- numOfRec++;
- printf(" %d. rect x=%d\ty=%d\tx2h=%d\ty2=%d\n",numOfRec,roi_x0,roi_y0,roi_x1,roi_y1);
- if(roi_x0 > roi_x1)
- {
- roi_x=roi_x1;
- roi_x1 = roi_x0;
- roi_x0 = roi_x;
- }
- if(roi_y0 > roi_y1)
- {
- roi_y=roi_y1;
- roi_y1 = roi_y0;
- roi_y0 = roi_y;
- }
- printf(" %d. rect x=%d\ty=%d\twidth=%d\theight=%d\n",numOfRec,roi_x0,roi_y0,roi_x1-roi_x0,roi_y1-roi_y0);
- strPostfix+=" "+IntToString(roi_x0)+" "+IntToString(roi_y0)+" "+IntToString(roi_x1-roi_x0)+" "+IntToString(roi_y1-roi_y0);
- cvRectangle(image,cvPoint(roi_x0,roi_y0),cvPoint(roi_x1,roi_y1),CV_RGB(0,0,205),5);
- break;
- }
- }
- while(iKey!='b');
- {
- // save to info file as later used for HaarTraining:
- if(numOfRec>0 && iKey=='b')
- {
- output << strPrefix << " "<< numOfRec << strPostfix <<"\n";
- cvReleaseImage(&image);
- }
- else
- {
- fprintf(stderr, "Failed to load image, %s\n", strPrefix.c_str());
- }
- }
- }
- }
-
- output.close();
- cvDestroyWindow(window_name);
- closedir(dir_p);
- cvWaitKey(0);
- return 0;
- }
/***************objectmarker.cpp******************
Objectmarker for marking the objects to be detected from positive samples and then creating the
description file for positive images.
compile this code and run with two arguments, first one the name of the descriptor file and the second one
the address of the directory in which the positive images are located
while running this code, each image in the given directory will open up. Now mark the edges of the object using the mouse buttons
then press then press "SPACE" to save the selected region, or any other key to discard it. Then use "b" to move to next image. the program automatically
quits at the end. press ESC at anytime to quit.
author: achu_wilson@rediffmail.com
author: provost.kevin@gmail.com
*/
#include <opencv/cv.h>
#include <opencv/cvaux.h>
#include <opencv/highgui.h>
// for filelisting
#include <stdio.h>
#include <io.h>
// for fileoutput
#include <string>
#include <fstream>
#include <sstream>
#include <dirent.h>
#include <sys/types.h>
using namespace std;
IplImage* image=0;
IplImage* image2=0;
int roi_x0=0;
int roi_y0=0;
int roi_x;
int roi_x1=0;
int roi_y1=0;
int roi_y;
int numOfRec=0;
int startDraw = 0;
char* window_name="<SPACE>add <b>save and load next <ESC>exit";
string IntToString(int num)
{
ostringstream myStream; //creates an ostringstream object
myStream << num << flush;
return(myStream.str()); //returns the string form of the stringstream object
};
void on_mouse(int event,int x,int y,int flag, void *param)
{
if(event==CV_EVENT_LBUTTONDOWN)
{
if(!startDraw)
{
roi_x0=x;
roi_y0=y;
startDraw = 1;
} else {
roi_x1=x;
roi_y1=y;
startDraw = 0;
}
}
if(event==CV_EVENT_MOUSEMOVE && startDraw)
{
//redraw ROI selection
image2=cvCloneImage(image);
cvRectangle(image2,cvPoint(roi_x0,roi_y0),cvPoint(x,y),CV_RGB(255,0,255),5);
cvShowImage(window_name,image2);
cvReleaseImage(&image2);
}
}
int main(int argc, char** argv)
{
char iKey=0;
string strPrefix;
string strPostfix;
string input_directory;
string output_file;
if(argc != 1)
{
fprintf(stderr, "%s output_info.txt raw/data/directory/\n", argv[0]);
return -1;
}
input_directory = argv[2];
output_file = argv[1];
/* Get a file listing of all files with in the input directory */
DIR *dir_p = opendir (input_directory.c_str());
struct dirent *dir_entry_p;
if(dir_p == NULL)
{
fprintf(stderr, "Failed to open directory %s\n", input_directory.c_str());
return -1;
}
fprintf(stderr, "Object Marker: Input Directory: %s Output File: %s\n", input_directory.c_str(), output_file.c_str());
// init highgui
cvAddSearchPath(input_directory);
cvNamedWindow(window_name,CV_WINDOW_KEEPRATIO);
cvSetMouseCallback(window_name,on_mouse, NULL);
fprintf(stderr, "Opening directory...");
// init output of rectangles to the info file
ofstream output(output_file.c_str());
fprintf(stderr, "done.\n");
while((dir_entry_p = readdir(dir_p)) != NULL)
{
numOfRec=0;
if(strcmp(dir_entry_p->d_name, ""))
fprintf(stderr, "Examining file %s\n", dir_entry_p->d_name);
strPostfix="";
strPrefix=input_directory;
fprintf(stderr, "Nom repertoire 1 %s\n", strPrefix.c_str());
strPrefix+=dir_entry_p->d_name;
fprintf(stderr, "Nom repertoire 2 %s\n", strPrefix.c_str());
fprintf(stderr, "Loading image %s\n", strPrefix.c_str());
image=cvLoadImage(strPrefix.c_str(),1);
printf("Valeure image %i \n", image);
//Work on current image
if(image != 0)
{
do
{
cvShowImage(window_name,image);
// used cvWaitKey returns:
// <b> save added rectangles and show next image
// <ESC>=27 exit program
// <Space>=32 add rectangle to current image
iKey=cvWaitKey(0);
switch(iKey)
{
case 27:
cvReleaseImage(&image);
cvDestroyWindow(window_name);
return 0;
case 32:
numOfRec++;
printf(" %d. rect x=%d\ty=%d\tx2h=%d\ty2=%d\n",numOfRec,roi_x0,roi_y0,roi_x1,roi_y1);
if(roi_x0 > roi_x1)
{
roi_x=roi_x1;
roi_x1 = roi_x0;
roi_x0 = roi_x;
}
if(roi_y0 > roi_y1)
{
roi_y=roi_y1;
roi_y1 = roi_y0;
roi_y0 = roi_y;
}
printf(" %d. rect x=%d\ty=%d\twidth=%d\theight=%d\n",numOfRec,roi_x0,roi_y0,roi_x1-roi_x0,roi_y1-roi_y0);
strPostfix+=" "+IntToString(roi_x0)+" "+IntToString(roi_y0)+" "+IntToString(roi_x1-roi_x0)+" "+IntToString(roi_y1-roi_y0);
cvRectangle(image,cvPoint(roi_x0,roi_y0),cvPoint(roi_x1,roi_y1),CV_RGB(0,0,205),5);
break;
}
}
while(iKey!='b');
{
// save to info file as later used for HaarTraining:
if(numOfRec>0 && iKey=='b')
{
output << strPrefix << " "<< numOfRec << strPostfix <<"\n";
cvReleaseImage(&image);
}
else
{
fprintf(stderr, "Failed to load image, %s\n", strPrefix.c_str());
}
}
}
}
output.close();
cvDestroyWindow(window_name);
closedir(dir_p);
cvWaitKey(0);
return 0;
}
Sources de la même categorie
Commentaires et avis
Discussions en rapport avec ce code source dans le forum
opencv utilisation [ par gaetanpouly ]
Bonjour, je desire utliser openCV mais j ai l erreur suivante essai fatal error LNK1104: impossible d'ouvrir le fichier 'C:\ProgramFiles\OpenCV\lib.o
opencv matlab transforme de fourier [ par CaMeGave ]
je dois faire des transforme de fourier avec OpenCV. Or lorsque je teste les resultats de la fonction cvDFT d'openCV avec la fonction fft2 de matlab
exemple avec librairie openCV [ par split2004 ]
Bonjour,Voila j'ai un projet assez important dont une partie avec du traitement de l'image.J'ai déjà installé la librairie OpenCV pour
OpenCV IPL AVI Nombre de trames : ( [ par kididouille ]
Bonjour à tous j'espere que quelqu'un pourra m'aider, voici ma requete: Je cherche à connaitre le nombre d'image qui composent un fichier AVI Pour lir
OpenCV library [ par mehdithe ]
Bonjour, Je travaille avec la bibliotheque OpenCv et je voudrais savoir quelle fonction pourrait me donner la valeur en niveau de gris d'un pixel d'u
opencv [ par elo29 ]
Bonjour!! Je dois, pour mon projet de fin d'études, récupérer et stocker en format bmp toutes les images filmées par ma caméra lorsque je lance
opencv [ par atefensi ]
je suis débutant j'utilise bib opencv pour traitement d'image en csvp quelqu'un peut dire c quoi la différence entre la structure cvmat et cvarr ds ce
opencv BIBLIO [ par atefensi ]
ds la bibliotheque opencv quel est la différence entre iplimage et cvmat? est ce qu'on peut utiliser simultanement la matrice comme de type iplimage
Problem d'excution [ par atefensi ]
Lorsque j'ai fais l'execution de mon programme,une fenetre apprait intitulé Opencv Gui error handler. Le message de la fenetre est:bad argument (ba
[OpenCV] Capturer le flux vidéo d'une carte pci [ par Mevag ]
Bonjour,J'ai réaliser un programme me permetant de traiter le flux vidéo à partir d'une WebCam usb pour réaliser une tetection de contour.Je souaite m
|
Derniers Blogs
VOTEZ POUR LE TOP 10 DES INFLUENCEURS SHAREPOINT FRANCOPHONES !VOTEZ POUR LE TOP 10 DES INFLUENCEURS SHAREPOINT FRANCOPHONES ! par Patrick Guimonet
Si ce n'est déjà fait (comme plus de 600 personnes déjà), il est encore temps de voter pour le concours TOP 10 des influenceurs SharePoint francophones ! Il est organisé par harmon.ie et accessible ici : http://harmon.ie/top-...
Cliquez pour lire la suite de l'article par Patrick Guimonet [CONF'SHAREPOINT] DERNIER RAPPEL ! :-)[CONF'SHAREPOINT] DERNIER RAPPEL ! :-) par Patrick Guimonet
La Conf'SharePoint en chiffres c'est : 3 jours de SharePoint ! 4 parcours et 60 sessions 17 partenaires représentant toutes les fac...
Cliquez pour lire la suite de l'article par Patrick Guimonet [ #SHAREPOINT 2013 ] LES MODèLES DE SITES STANDARDS.[ #SHAREPOINT 2013 ] LES MODèLES DE SITES STANDARDS. par Patrick Guimonet
C'est un point peu mis en avant mais SharePoint 2013 a été l'occasion de remettre de l'ordre dans les modèles de sites. Tout d'abord, un certain nombre de modèles ont été tout simplement rendus obsolètes (cf. Fonctionnalités déco...
Cliquez pour lire la suite de l'article par Patrick Guimonet 10 ERREURS DE COMPRéHENSION CONCERNANT SHAREPOINT.10 ERREURS DE COMPRéHENSION CONCERNANT SHAREPOINT. par Patrick Guimonet
Une excellente infographie (qui a sa source ici :http://www.evokeit.com/sharepoint-blog/misconceptions-of-microsoft-sharepoint) que j'ai traduite et commentée sur le blog d'Abalon : http://abalon.fr/blog/10-erreurs-de-comprhension-...
Cliquez pour lire la suite de l'article par Patrick Guimonet
Forum
MINI PROJETMINI PROJET par codexana
Cliquez pour lire la suite par codexana
Logiciels
Nego Facturation (1.84)NEGO FACTURATION (1.84)Nego Facturation est un logiciel complet qui permet de gérer vos factures et devis très simplemen... Cliquez pour télécharger Nego Facturation Revealer Keylogger Free (2.07)REVEALER KEYLOGGER FREE (2.07)Keylogger invisible et gratuit pour Windows 8, 7, Vista ou XP. Revealer Keylogger Free vous perme... Cliquez pour télécharger Revealer Keylogger Free Devis-Factures PHMSD (2.1.0.1)DEVIS-FACTURES PHMSD (2.1.0.1)Configuration minimale
Nécessite Windows™ 2000, XP, Windows 7, 8, Vista (Service Pack à... Cliquez pour télécharger Devis-Factures PHMSD Ludoprêt (3.2)LUDOPRêT (3.2)Logiciel gratuit de gestion de ludothèque.
Gestion des jeux et des adhérents.
Gestion des for... Cliquez pour télécharger Ludoprêt 974 Application Server (13.2.1.3)974 APPLICATION SERVER (13.2.1.3)Ecommerce, Blogueur, Vitrine, Newsletter, Java IDE, ..., in the cloud et sous haute dispo. Facile... Cliquez pour télécharger 974 Application Server
|