PageRenderTime 125ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/0.1-release/gtk-facemanager.c

http://pam-face-authentication.googlecode.com/
C | 686 lines | 538 code | 52 blank | 96 comment | 58 complexity | 55655d705e291b8e84ba8a38931f56b1 MD5 | raw file
Possible License(s): GPL-2.0, GPL-3.0
  1. /*
  2. Copyright (C) 2008 Rohan Anil (rohan.anil@gmail.com) , Alex Lau ( avengermojo@gmail.com)
  3. Google Summer of Code Program 2008
  4. Mentoring Organization: openSUSE
  5. Mentor: Alex Lau
  6. This program is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include <gtk/gtk.h>
  18. #include "highgui.h"
  19. #include "cv.h"
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <string.h>
  23. #include <assert.h>
  24. #include <math.h>
  25. #include <float.h>
  26. #include <limits.h>
  27. #include <time.h>
  28. #include <ctype.h>
  29. #include <dlfcn.h>
  30. #include <sys/types.h>
  31. #include <sys/ipc.h>
  32. #include <sys/shm.h>
  33. #include <unistd.h>
  34. #include "pam_face_defines.h"
  35. CvMemStorage* storageFace;
  36. CvMemStorage* storageEyeLeft;
  37. CvMemStorage* storageEyeRight;
  38. CvMemStorage* storageNose;
  39. CvHaarClassifierCascade* cascadeFace;
  40. CvHaarClassifierCascade* cascadeEyeLeft;
  41. CvHaarClassifierCascade* cascadeEyeRight;
  42. CvHaarClassifierCascade* cascadeNose;
  43. GtkBuilder *builder;
  44. GtkBuilder *builderIN;
  45. IplImage *frame,*frameNew, *frame_copy = 0;
  46. CvPoint pLeftEye;
  47. CvPoint pRightEye;
  48. CvCapture* capture;
  49. int captureFace=-1;
  50. int numberOfFacesToCapture=6;
  51. void *handleFaceDetect;
  52. void *handleFaceConfigure;
  53. int (*faceDetect)( IplImage* ,CvPoint *,CvPoint *,CvMemStorage* ,CvMemStorage* ,CvMemStorage* ,CvMemStorage* ,CvHaarClassifierCascade* ,CvHaarClassifierCascade* ,CvHaarClassifierCascade* ,CvHaarClassifierCascade* );
  54. int (*preprocess)( IplImage* ,CvPoint ,CvPoint, IplImage* );
  55. void (*learn)();
  56. char* NONE_SELECTED="No User Selected";
  57. enum
  58. {
  59. USER_NAME = 0,
  60. STATUS,
  61. N_COLUMNS
  62. };
  63. void loadCVPIXBUF(GtkWidget *imgCapturedFace,IplImage* image)
  64. {
  65. unsigned char *gdataUserFace;
  66. GdkPixbuf *pixbufUserFace= NULL;
  67. pixbufUserFace = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE,8,image->width,image->height);
  68. gdataUserFace = gdk_pixbuf_get_pixels(pixbufUserFace);
  69. int m,n;
  70. for (n=0;n<image->height;n++)
  71. {
  72. for (m= 0;m<image->width;m++)
  73. {
  74. CvScalar s;
  75. s=cvGet2D(image,n,m);
  76. gdataUserFace[n*image->width*3 + m*3 +0]=(uchar)s.val[2];
  77. gdataUserFace[n*image->width*3 + m*3 +1]=(uchar)s.val[1];
  78. gdataUserFace[n*image->width*3 + m*3 +2]=(uchar)s.val[0];
  79. }
  80. }
  81. gtk_image_set_from_pixbuf(imgCapturedFace, pixbufUserFace);
  82. g_object_unref (pixbufUserFace);
  83. }
  84. void loadFaceImage(char *fullPath,GtkWidget *img)
  85. {
  86. IplImage* image =0;
  87. image=cvLoadImage( fullPath, 1 );
  88. if (image!=NULL)
  89. loadCVPIXBUF(img,image);
  90. else
  91. {
  92. image= cvCreateImage( cvSize(120,140),8,1);
  93. cvZero(image);
  94. loadCVPIXBUF(img,image);
  95. }
  96. }
  97. void saveConfigFile()
  98. {
  99. FILE *file1;
  100. GtkWidget *tvList;
  101. tvList = GTK_WIDGET (gtk_builder_get_object (builder, "tvList"));
  102. GtkListStore *store;
  103. GtkTreeModel *model;
  104. GtkTreeIter iter;
  105. store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW (tvList)));
  106. model = gtk_tree_view_get_model (GTK_TREE_VIEW (tvList));
  107. if (file1 = fopen(GTK_FACE_MANAGER_KEY, "w"))
  108. {
  109. if (gtk_tree_model_get_iter_first(model, &iter) != FALSE)
  110. {
  111. char *value,*value1;
  112. char *fullPath;
  113. char * t="Assigned";
  114. gtk_tree_model_get(model, &iter, USER_NAME, &value,STATUS, &value1, -1);
  115. if (strcmp(value1,t)==0)
  116. {
  117. // no itoa
  118. int i;
  119. for (i=1;i<7;i++)
  120. {
  121. char * ch=(char *)calloc(2,sizeof(char));
  122. if (i==1)
  123. strcat(ch,"1");
  124. if (i==2)
  125. strcat(ch,"2");
  126. if (i==3)
  127. strcat(ch,"3");
  128. if (i==4)
  129. strcat(ch,"4");
  130. if (i==5)
  131. strcat(ch,"5");
  132. if (i==6)
  133. strcat(ch,"6");
  134. fullPath=(char *)calloc( strlen(imgPath) + strlen(value)+strlen(imgExt)+2,sizeof(char));
  135. strcat(fullPath,imgPath);
  136. strcat(fullPath,value);
  137. strcat(fullPath,ch);
  138. strcat(fullPath,imgExt);
  139. fprintf(file1,"%s %s\n",value, fullPath);
  140. }
  141. }
  142. g_free(value);
  143. g_free(value1);
  144. while (gtk_tree_model_iter_next (model, &iter)!=FALSE)
  145. {
  146. gtk_tree_model_get(model, &iter, USER_NAME, &value,STATUS, &value1, -1);
  147. if (strcmp(value1,t)==0)
  148. {
  149. int i;
  150. for (i=1;i<7;i++)
  151. {
  152. char * ch=(char *)calloc(2,sizeof(char));
  153. if (i==1)
  154. strcat(ch,"1");
  155. if (i==2)
  156. strcat(ch,"2");
  157. if (i==3)
  158. strcat(ch,"3");
  159. if (i==4)
  160. strcat(ch,"4");
  161. if (i==5)
  162. strcat(ch,"5");
  163. if (i==6)
  164. strcat(ch,"6");
  165. fullPath=(char *)calloc( strlen(imgPath) + strlen(value)+strlen(imgExt)+2,sizeof(char));
  166. strcat(fullPath,imgPath);
  167. strcat(fullPath,value);
  168. strcat(fullPath,ch);
  169. strcat(fullPath,imgExt);
  170. fprintf(file1,"%s %s\n",value, fullPath);
  171. }
  172. }
  173. }
  174. }
  175. }
  176. // printf("dleror is %s \n",dlerror());
  177. fclose(file1);
  178. }
  179. void
  180. on_btnSSave_clicked (GtkButton *button,gpointer user_data)
  181. {
  182. saveConfigFile();
  183. // learn();
  184. GtkWidget *inpDialog;
  185. inpDialog = GTK_WIDGET (gtk_builder_get_object (builder, "dlgSampleFace"));
  186. gtk_widget_hide(inpDialog);
  187. }
  188. void
  189. on_btnInpOk_clicked (GtkButton *button,gpointer user_data)
  190. {
  191. GtkWidget *inpDialog;
  192. inpDialog = GTK_WIDGET (gtk_builder_get_object (builder, "dlgInputUserName"));
  193. char *text[2];
  194. char *b="Not Assigned";
  195. text[0]=(char *)gtk_entry_get_text (GTK_ENTRY(GTK_WIDGET (gtk_builder_get_object (builder, "entUserName"))));
  196. text[1]=b;
  197. GtkListStore *store;
  198. GtkTreeIter iter;
  199. store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(GTK_WIDGET (gtk_builder_get_object (builder, "tvList")))));
  200. gtk_list_store_append(store, &iter);
  201. gtk_list_store_set(store, &iter, USER_NAME, text[0],STATUS,text[1], -1);
  202. gtk_widget_hide(inpDialog);
  203. }
  204. void
  205. on_btnSCancel_clicked (GtkButton *button,gpointer user_data)
  206. {
  207. GtkWidget *inpDialog;
  208. inpDialog = GTK_WIDGET (gtk_builder_get_object (builder, "dlgSampleFace"));
  209. gtk_widget_hide(inpDialog);
  210. }
  211. void
  212. on_btnSFace_clicked (GtkButton *button,gpointer user_data)
  213. {
  214. captureFace=6;
  215. }
  216. void
  217. on_btnInpCancel_clicked (GtkButton *button,gpointer user_data)
  218. {
  219. GtkWidget *inpDialog;
  220. inpDialog = GTK_WIDGET (gtk_builder_get_object (builder, "dlgInputUserName"));
  221. gtk_widget_hide(inpDialog);
  222. }
  223. char * fileNameImage(char *ch,char *value)
  224. {
  225. char *fullPath;
  226. fullPath=(char *)calloc( strlen(imgPath) + strlen(value)+strlen(imgExt)+2,sizeof(char));
  227. strcat(fullPath,imgPath);
  228. strcat(fullPath,value);
  229. strcat(fullPath,ch);
  230. strcat(fullPath,imgExt);
  231. return fullPath;
  232. }
  233. void
  234. on_btnTrain_clicked (GtkButton *button,gpointer user_data)
  235. {
  236. GtkTreeSelection *selection;
  237. GtkWidget *tvList;
  238. tvList = GTK_WIDGET (gtk_builder_get_object (builder, "tvList"));
  239. selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tvList));
  240. GtkTreeIter iter;
  241. GtkTreeModel *model;
  242. char *value;
  243. if (gtk_tree_selection_get_selected(GTK_TREE_SELECTION(selection), &model, &iter))
  244. {
  245. gtk_tree_model_get(model, &iter, USER_NAME, &value, -1);
  246. GtkResponseType val;
  247. GtkWidget *inpDialog;
  248. GtkWidget *imgS;
  249. inpDialog = GTK_WIDGET (gtk_builder_get_object (builder, "dlgSampleFace"));
  250. IplImage *face;
  251. face = cvCreateImage( cvSize(120,140),8,3);
  252. cvZero(face);
  253. face=cvLoadImage(fileNameImage("1",value), 1 );
  254. if (face!=0)
  255. {
  256. imgS = GTK_WIDGET (gtk_builder_get_object (builder, "imgS1"));
  257. loadCVPIXBUF(imgS,face);
  258. }
  259. face=cvLoadImage(fileNameImage("2",value), 1 );
  260. if (face!=0)
  261. {
  262. imgS = GTK_WIDGET (gtk_builder_get_object (builder, "imgS2"));
  263. loadCVPIXBUF(imgS,face);
  264. }
  265. face=cvLoadImage(fileNameImage("3",value), 1 );
  266. if (face!=0)
  267. {
  268. imgS = GTK_WIDGET (gtk_builder_get_object (builder, "imgS3"));
  269. loadCVPIXBUF(imgS,face);
  270. }
  271. face=cvLoadImage(fileNameImage("4",value), 1 );
  272. if (face!=0)
  273. {
  274. imgS = GTK_WIDGET (gtk_builder_get_object (builder, "imgS4"));
  275. loadCVPIXBUF(imgS,face);
  276. }
  277. face=cvLoadImage(fileNameImage("5",value), 1 );
  278. if (face!=0)
  279. {
  280. imgS = GTK_WIDGET (gtk_builder_get_object (builder, "imgS5"));
  281. loadCVPIXBUF(imgS,face);
  282. }
  283. face=cvLoadImage(fileNameImage("6",value), 1 );
  284. if (face!=0)
  285. {
  286. imgS = GTK_WIDGET (gtk_builder_get_object (builder, "imgS6"));
  287. loadCVPIXBUF(imgS,face);
  288. }
  289. val=gtk_dialog_run(GTK_DIALOG(inpDialog));
  290. }
  291. }
  292. void
  293. on_btnAbout_clicked (GtkButton *button,gpointer user_data)
  294. {
  295. /*
  296. GtkWidget *abtProj;
  297. abtProj = GTK_WIDGET (gtk_builder_get_object (builder, "abtProj"));
  298. gtk_dialog_run(abtProj);
  299. gtk_widget_hide(abtProj);
  300. */
  301. GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file("battery.png", NULL);
  302. GtkWidget *dialog = gtk_about_dialog_new();
  303. gtk_about_dialog_set_name(GTK_ABOUT_DIALOG(dialog), "PAM FACE AUTHENTICATION");
  304. gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(dialog), "0.1");
  305. gtk_about_dialog_set_copyright(GTK_ABOUT_DIALOG(dialog),"Work done during Google Summer of Code 2008 for openSUSE by Rohan Anil and mentored by Alex Lau");
  306. gtk_about_dialog_set_comments(GTK_ABOUT_DIALOG(dialog),
  307. "PAM Module for Face Recognition.");
  308. gtk_about_dialog_set_website(GTK_ABOUT_DIALOG(dialog),
  309. "http://code.google.com/p/pam-face-authentication/");
  310. //gtk_about_dialog_set_logo(GTK_ABOUT_DIALOG(dialog), pixbuf);
  311. //g_object_unref(pixbuf), pixbuf = NULL;
  312. gtk_dialog_run(GTK_DIALOG (dialog));
  313. gtk_widget_destroy(dialog);
  314. }
  315. GtkResponseType showYesNo(char * str)
  316. {
  317. GtkResponseType response;
  318. GtkWidget *dialog;
  319. dialog = gtk_message_dialog_new(NULL,GTK_DIALOG_DESTROY_WITH_PARENT,
  320. GTK_MESSAGE_QUESTION,GTK_BUTTONS_YES_NO,
  321. str);
  322. gtk_window_set_title(GTK_WINDOW(dialog), "Face Manager");
  323. response=gtk_dialog_run(GTK_DIALOG(dialog));
  324. gtk_widget_destroy(dialog);
  325. return response;
  326. }
  327. void
  328. on_btnCaptureFace_clicked (GtkButton *button,gpointer user_data)
  329. {
  330. captureFace=6;
  331. }
  332. void
  333. on_btnQuit_clicked (GtkButton *button,gpointer user_data)
  334. {
  335. char * str= "Are you sure to quit?";
  336. if (showYesNo(str)==GTK_RESPONSE_YES)
  337. {
  338. gtk_main_quit();
  339. }
  340. }
  341. void
  342. on_btnAdd_clicked (GtkButton *button,gpointer user_data)
  343. {
  344. GtkResponseType val;
  345. GtkWidget *inpDialog;
  346. inpDialog = GTK_WIDGET (gtk_builder_get_object (builder, "dlgInputUserName"));
  347. val=gtk_dialog_run(GTK_DIALOG(inpDialog));
  348. gtk_widget_hide(inpDialog);
  349. }
  350. void
  351. on_btnRemove_clicked (GtkButton *button,gpointer user_data)
  352. {
  353. GtkWidget *tvList;
  354. tvList = GTK_WIDGET (gtk_builder_get_object (builder, "tvList"));
  355. GtkListStore *store;
  356. GtkTreeModel *model;
  357. GtkTreeIter iter;
  358. GtkTreeSelection *selection;
  359. selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tvList));
  360. store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW (tvList)));
  361. model = gtk_tree_view_get_model (GTK_TREE_VIEW (tvList));
  362. if (gtk_tree_model_get_iter_first(model, &iter) == FALSE)
  363. return;
  364. if (gtk_tree_selection_get_selected(GTK_TREE_SELECTION(selection),&model, &iter))
  365. {
  366. char * str= "Do you want to remove from the List?";
  367. if (showYesNo(str)==GTK_RESPONSE_YES)
  368. {
  369. gtk_list_store_remove(store, &iter);
  370. saveConfigFile();
  371. }
  372. }
  373. }
  374. static void
  375. init_list(GtkWidget *list)
  376. {
  377. GtkCellRenderer *renderer;
  378. GtkTreeViewColumn *column;
  379. GtkListStore *store;
  380. renderer = gtk_cell_renderer_text_new();
  381. column = gtk_tree_view_column_new_with_attributes("User Name",renderer, "text", USER_NAME, NULL);
  382. gtk_tree_view_append_column(GTK_TREE_VIEW(list), column);
  383. column = gtk_tree_view_column_new_with_attributes("Status",renderer, "text", STATUS, NULL);
  384. gtk_tree_view_append_column(GTK_TREE_VIEW(list), column);
  385. store = gtk_list_store_new(N_COLUMNS, G_TYPE_STRING,G_TYPE_STRING);
  386. gtk_tree_view_set_model(GTK_TREE_VIEW(list),GTK_TREE_MODEL(store));
  387. g_object_unref(store);
  388. }
  389. static void
  390. add_to_list(GtkWidget *list, const gchar *str1,const gchar *str2)
  391. {
  392. GtkListStore *store;
  393. GtkTreeIter iter;
  394. store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(list)));
  395. gtk_list_store_append(store, &iter);
  396. gtk_list_store_set(store, &iter, USER_NAME, str1,STATUS, str2,-1);
  397. }
  398. void createListItems(GtkWidget *tvList)
  399. {
  400. char tempUserName[512];
  401. char imgFilename[512];
  402. FILE* file1;
  403. if (file1 = fopen(GTK_FACE_MANAGER_KEY, "r"))
  404. {
  405. while (fscanf(file1,"%s %s", tempUserName, imgFilename)!=EOF )
  406. {
  407. int i=0;
  408. for (i=0;i<5;i++)
  409. fscanf(file1,"%s %s", tempUserName, imgFilename);
  410. char *text[2];
  411. char *b="Assigned";
  412. text[0]=tempUserName;
  413. text[1]=b;
  414. add_to_list(tvList, text[0],b);
  415. }
  416. }
  417. }
  418. /*
  419. void on_changed(GtkWidget *widget, gpointer label)
  420. {
  421. selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tvList));
  422. GtkTreeIter iter;
  423. GtkTreeModel *model;
  424. char *value;
  425. GtkWidget *lblUserName;
  426. if (gtk_tree_selection_get_selected(GTK_TREE_SELECTION(widget), &model, &iter))
  427. {
  428. gtk_tree_model_get(model, &iter, USER_NAME, &value, -1);
  429. // lblUserName = GTK_WIDGET (gtk_builder_get_object (builder, "lblUserName"));
  430. // gtk_label_set_text(GTK_LABEL(lblUserName), value);
  431. // hideShowSelectArea(1);
  432. loadFaceImage(value);
  433. g_free(value);
  434. }
  435. else
  436. {
  437. // lblUserName = GTK_WIDGET (gtk_builder_get_object (builder, "lblUserName"));
  438. // gtk_label_set_text(GTK_LABEL(lblUserName),NONE_SELECTED);
  439. // hideShowSelectArea(0);
  440. }
  441. }
  442. */
  443. /*
  444. void hideShowSelectArea(int t)
  445. {
  446. GtkWidget *imgCapturedFace;
  447. GtkWidget *btnCaptureFace;
  448. imgCapturedFace = GTK_WIDGET (gtk_builder_get_object (builder, "imgCapturedFace"));
  449. btnCaptureFace = GTK_WIDGET (gtk_builder_get_object (builder, "btnCaptureFace"));
  450. if (t==1)
  451. {
  452. GdkPixbuf *pixbuf = NULL;
  453. pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE,8,320,240);
  454. gtk_image_set_from_pixbuf(imgCapturedFace, pixbuf);
  455. gtk_widget_show (btnCaptureFace);
  456. gtk_widget_show (imgCapturedFace);
  457. }
  458. if (t==0)
  459. {
  460. gtk_widget_hide (btnCaptureFace);
  461. gtk_widget_hide (imgCapturedFace);
  462. }
  463. }
  464. */
  465. void intialize()
  466. {
  467. cascadeFace = (CvHaarClassifierCascade*)cvLoad( HAAR_CASCADE_FACE, 0, 0, 0 );
  468. cascadeEyeLeft = (CvHaarClassifierCascade*)cvLoad( HAAR_CASCADE_EYE, 0, 0, 0 );
  469. cascadeEyeRight = (CvHaarClassifierCascade*)cvLoad( HAAR_CASCADE_EYE, 0, 0, 0 );
  470. cascadeNose = (CvHaarClassifierCascade*)cvLoad( HAAR_CASCADE_NOSE, 0, 0, 0 );
  471. storageFace = cvCreateMemStorage(0);
  472. storageEyeLeft = cvCreateMemStorage(0);
  473. storageEyeRight = cvCreateMemStorage(0);
  474. storageNose = cvCreateMemStorage(0);
  475. }
  476. void allocateMemory()
  477. {
  478. cvClearMemStorage(storageFace );
  479. cvClearMemStorage( storageNose );
  480. cvClearMemStorage( storageEyeLeft );
  481. cvClearMemStorage( storageEyeRight );
  482. }
  483. static gboolean time_handler(GtkWidget *widget)
  484. {
  485. if (widget->window == NULL) return FALSE;
  486. if ( !cvGrabFrame( capture ))
  487. return FALSE;
  488. frame = cvRetrieveFrame( capture );
  489. if ( !frame )
  490. return FALSE;
  491. if ( !frame_copy )
  492. {
  493. frame_copy = cvCreateImage( cvSize(frame->width,frame->height),IPL_DEPTH_8U, frame->nChannels );
  494. frameNew = cvCreateImage( cvSize(frame->width,frame->height),IPL_DEPTH_8U, frame->nChannels );
  495. }
  496. if ( frame->origin == IPL_ORIGIN_TL )
  497. cvCopy( frame, frame_copy, 0 );
  498. else
  499. cvFlip( frame, frame_copy, 0 );
  500. cvCopy( frame_copy, frameNew, 0 );
  501. allocateMemory();
  502. int k= faceDetect(frame_copy,&pLeftEye,&pRightEye,storageFace,storageEyeLeft,storageEyeRight, storageNose, cascadeFace,cascadeEyeLeft,cascadeEyeRight,cascadeNose);
  503. if (k==1 && captureFace>0)
  504. {
  505. IplImage *face;
  506. face = cvCreateImage( cvSize(120,140),8,1);
  507. int j= preprocess(frameNew,pLeftEye,pRightEye,face);
  508. GtkTreeIter iter;
  509. GtkTreeModel *model;
  510. char *value;
  511. char *b="Assigned";
  512. GtkListStore *store;
  513. GtkWidget *widget;
  514. GtkWidget *selection;
  515. widget = GTK_WIDGET (gtk_builder_get_object (builder, "tvList"));
  516. selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
  517. if (gtk_tree_selection_get_selected(GTK_TREE_SELECTION(selection), &model, &iter))
  518. {
  519. gtk_tree_model_get(model, &iter, USER_NAME, &value, -1);
  520. char *fullPath;
  521. fullPath=(char *)calloc( strlen(imgPath) + strlen(value)+strlen(imgExt)+1+1,sizeof(char));
  522. strcat(fullPath,imgPath);
  523. strcat(fullPath,value);
  524. char * ch=(char *)calloc(2,sizeof(char));
  525. GtkWidget *imgS;
  526. if ((numberOfFacesToCapture-captureFace)==0)
  527. {
  528. strcat(ch,"1");
  529. imgS = GTK_WIDGET (gtk_builder_get_object (builder,"imgS1"));
  530. }
  531. if ((numberOfFacesToCapture-captureFace)==1)
  532. {
  533. strcat(ch,"2");
  534. imgS = GTK_WIDGET (gtk_builder_get_object (builder,"imgS2"));
  535. }
  536. if ((numberOfFacesToCapture-captureFace)==2)
  537. {
  538. strcat(ch,"3");
  539. imgS = GTK_WIDGET (gtk_builder_get_object (builder,"imgS3"));
  540. }
  541. if ((numberOfFacesToCapture-captureFace)==3)
  542. {
  543. strcat(ch,"4");
  544. imgS = GTK_WIDGET (gtk_builder_get_object (builder,"imgS4"));
  545. }
  546. if ((numberOfFacesToCapture-captureFace)==4)
  547. {
  548. strcat(ch,"5");
  549. imgS = GTK_WIDGET (gtk_builder_get_object (builder,"imgS5"));
  550. }
  551. if ((numberOfFacesToCapture-captureFace)==5)
  552. {
  553. strcat(ch,"6");
  554. imgS = GTK_WIDGET (gtk_builder_get_object (builder,"imgS6"));
  555. }
  556. strcat(fullPath,ch);
  557. strcat(fullPath,imgExt);
  558. cvSaveImage(fullPath,face);
  559. if ((numberOfFacesToCapture-captureFace)>=0 &&(numberOfFacesToCapture-captureFace)<=5)
  560. loadFaceImage(fullPath,imgS);
  561. //loadCVPIXBUF(imgS,face);
  562. // on_changed(selection,NULL);
  563. }
  564. if (j==1)
  565. {
  566. // loadCVPIXBUF(simage,face);
  567. captureFace--;
  568. if (captureFace==0)
  569. {
  570. store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(GTK_WIDGET (gtk_builder_get_object (builder, "tvList")))));
  571. gtk_list_store_set(store, &iter, USER_NAME, value,STATUS,b, -1);
  572. }
  573. }
  574. }
  575. /* GtkWidget *imgWebcam;
  576. imgWebcam = GTK_WIDGET (gtk_builder_get_object (builder, "imgWebcam"));
  577. loadCVPIXBUF(imgWebcam,frame_copy);
  578. */
  579. GtkWidget *imgSWebcam;
  580. imgSWebcam = GTK_WIDGET (gtk_builder_get_object (builder, "imgSWebcam"));
  581. loadCVPIXBUF(imgSWebcam,frame_copy);
  582. if ( cvWaitKey( 4 ) >= 0 )
  583. {}
  584. return TRUE;
  585. }
  586. int
  587. main (int argc, char *argv[])
  588. {
  589. handleFaceDetect = dlopen(FACE_DETECT_LIBRARY, RTLD_LAZY);
  590. faceDetect = dlsym(handleFaceDetect, "faceDetect");
  591. preprocess = dlsym(handleFaceDetect, "preprocess");
  592. // dlerror();
  593. handleFaceConfigure = dlopen(FACE_CONFIGURE_LIBRARY, RTLD_NOW);
  594. learn = dlsym(handleFaceConfigure, "learn");
  595. //printf("ERROR %s \n",dlerror());
  596. intialize();
  597. capture = cvCaptureFromCAM(0);
  598. GtkWidget *window;
  599. GtkWidget *windowIN;
  600. GtkWidget *tvList;
  601. GtkTreeSelection *selection;
  602. GtkWidget *lblUserName;
  603. GtkWidget *inpDialog;
  604. gtk_init (&argc, &argv);
  605. builder = gtk_builder_new ();
  606. builderIN = gtk_builder_new ();
  607. gtk_builder_add_from_file (builder, XML_GTK_BUILDER_FACE_MANAGER, NULL);
  608. window = GTK_WIDGET (gtk_builder_get_object (builder, "gtk-facemanager"));
  609. tvList = GTK_WIDGET (gtk_builder_get_object (builder, "tvList"));
  610. inpDialog = GTK_WIDGET (gtk_builder_get_object (builder, "dlgInputUserName"));
  611. gtk_widget_hide(inpDialog);
  612. g_timeout_add(100, (GSourceFunc) time_handler, (gpointer) window);
  613. gtk_builder_connect_signals (builder, NULL);
  614. init_list(tvList);
  615. createListItems(tvList);
  616. // hideShowSelectArea(0);
  617. // lblUserName = GTK_WIDGET (gtk_builder_get_object (builder, "lblUserName"));
  618. // gtk_label_set_text(GTK_LABEL(lblUserName),NONE_SELECTED);
  619. selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tvList));
  620. // g_signal_connect(selection, "changed",G_CALLBACK(on_changed),NULL);
  621. gtk_widget_show (window);
  622. gtk_main ();
  623. g_object_unref (G_OBJECT (builder));
  624. return 0;
  625. }