add base code
[framework/api/face.git] / TC / testcase / utc_uix_face_detect_video_negative.c
1 /*
2  *
3  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4  * PROPRIETARY/CONFIDENTIAL
5  *
6  * This software is the confidential and proprietary information of SAMSUNG
7  * ELECTRONICS ("Confidential Information"). You agree and acknowledge that
8  * this software is owned by Samsung and you shall not disclose such
9  * Confidential Information and shall use it only in accordance with the terms
10  * of the license agreement you entered into with SAMSUNG ELECTRONICS. SAMSUNG
11  * make no representations or warranties about the suitability of the software,
12  * either express or implied, including but not limited to the implied
13  * warranties of merchantability, fitness for a particular purpose, or
14  * non-infringement. SAMSUNG shall not be liable for any damages suffered by
15  * licensee arising out of or related to this software.
16  *
17  */
18 #include <stdio.h>
19 #include <tet_api.h>
20
21 #include <face.h>
22
23 static void startup(void);
24 static void cleanup(void);
25
26 void (*tet_startup)(void) = startup;
27 void (*tet_cleanup)(void) = cleanup;
28
29
30 #define TESTVIDEO_NAME (DATADIR"suzie_qcif.yuv")
31 #define TESTVIDEO_WIDTH (176)
32 #define TESTVIDEO_HEIGHT (144)
33 #define TESTVIDEO_FRAME (10)
34
35 static void startup(void)
36 {
37 // TODO : How to copy sample image????
38 }
39
40 static void cleanup(void)
41 {
42         /* end of TC */
43 }
44
45
46 static void utc_uix_face_detect_faces_from_video_stream_negative_01(void)
47 {
48         static const char szFunc[] = "face_detect_faces_from_video_stream";
49
50         int err;
51
52         face_h face;
53
54     err = face_create(&face);
55
56         char *filename = TESTVIDEO_NAME;
57         int nW = TESTVIDEO_WIDTH;
58         int nH = TESTVIDEO_HEIGHT;
59
60         unsigned char YBuf[nW*nH];
61
62         FILE *fp;
63         int nRead;
64
65         fp = fopen(filename, "rb");
66
67
68         face_image_h image;
69
70         int nCount = 0;
71
72         face_rect_s *rects = NULL;
73
74         int i;
75         for ( i = 0; i < TESTVIDEO_FRAME; i++)
76         {
77                 nRead = fread (YBuf, 1, nW * nH, fp );
78
79                 if ( nRead != nW * nH )
80                 {
81                         // Error
82                         tet_printf("Wanted %d bytes Read %d bytes\n", nW * nH, nRead);
83                         tet_result(TET_UNRESOLVED);
84                         return ;
85                 }
86
87                 face_image_create(FACE_IMAGE_COLORSPACE_LUMINANCE_ONLY, YBuf, nW, nH, nW * nH, &image);
88
89                 err = face_detect_faces(face, FACE_IMAGE_TYPE_CONTINIOUS, image, NULL, &nCount );
90                 dts_check_ne(szFunc, err, FACE_ERROR_NONE);
91
92                 face_image_destroy(image);
93
94         }
95
96         err = face_destroy(face);
97
98         fclose(fp);
99
100 }
101
102 static void utc_uix_face_detect_faces_from_video_stream_negative_02(void)
103 {
104         static const char szFunc[] = "face_detect_faces_from_video_stream";
105
106         int err;
107
108         face_h face;
109
110     err = face_create(&face);
111
112         char *filename = TESTVIDEO_NAME;
113         int nW = TESTVIDEO_WIDTH;
114         int nH = TESTVIDEO_HEIGHT;
115
116         unsigned char YBuf[nW*nH];
117
118         FILE *fp;
119         int nRead;
120
121         fp = fopen(filename, "rb");
122
123
124         face_image_h image;
125
126         int nCount = 0;
127
128         face_rect_s *rects = NULL;
129
130         int i;
131         for ( i = 0; i < TESTVIDEO_FRAME; i++)
132         {
133                 nRead = fread (YBuf, 1, nW * nH, fp );
134
135                 if ( nRead != nW * nH )
136                 {
137                         // Error
138                         tet_printf("Wanted %d bytes Read %d bytes\n", nW * nH, nRead);
139                         tet_result(TET_UNRESOLVED);
140                         return ;
141                 }
142
143                 face_image_create(FACE_IMAGE_COLORSPACE_LUMINANCE_ONLY, YBuf, nW, nH, nW * nH, &image);
144
145                 err = face_detect_faces(face, FACE_IMAGE_TYPE_CONTINIOUS, image, &rects, NULL );
146                 dts_check_ne(szFunc, err, FACE_ERROR_NONE);
147
148                 face_image_destroy(image);
149         }
150
151         err = face_destroy(face);
152
153         fclose(fp);
154
155 }
156
157
158
159 static void utc_uix_face_detect_faces_from_video_stream_negative_03(void)
160 {
161         static const char szFunc[] = "face_detect_faces_from_video_stream";
162
163         int err;
164
165         face_h face;
166
167     err = face_create(&face);
168
169         char *filename = TESTVIDEO_NAME;
170         int nW = TESTVIDEO_WIDTH;
171         int nH = TESTVIDEO_HEIGHT;
172
173         unsigned char YBuf[nW*nH];
174
175         FILE *fp;
176         int nRead;
177
178         fp = fopen(filename, "rb");
179
180
181         face_image_h image;
182
183         int nCount = 0;
184
185         face_rect_s *rects = NULL;
186
187         int i;
188         for ( i = 0; i < TESTVIDEO_FRAME; i++)
189         {
190                 nRead = fread (YBuf, 1, nW * nH, fp );
191
192                 if ( nRead != nW * nH )
193                 {
194                         // Error
195                         tet_printf("Wanted %d bytes Read %d bytes\n", nW * nH, nRead);
196                         tet_result(TET_UNRESOLVED);
197                         return ;
198                 }
199
200                 face_image_create(FACE_IMAGE_COLORSPACE_LUMINANCE_ONLY, YBuf, nW, nH, nW * nH, &image);
201
202                 err = face_detect_faces(face, FACE_IMAGE_TYPE_CONTINIOUS, NULL, &rects, &nCount );
203                 dts_check_ne(szFunc, err, FACE_ERROR_NONE);
204
205                 face_image_destroy(image);
206         }
207
208         err = face_destroy(face);
209
210         fclose(fp);
211
212 }
213
214
215 static void utc_uix_face_extract_component_negative_01(void)
216 {
217         static const char szFunc[] = "face_extract_component";
218
219         int err;
220
221         face_h face;
222
223     err = face_create(&face);
224
225         char *filename = TESTVIDEO_NAME;
226         int nW = TESTVIDEO_WIDTH;
227         int nH = TESTVIDEO_HEIGHT;
228
229         unsigned char YBuf[nW*nH];
230
231         FILE *fp;
232         int nRead;
233
234         fp = fopen(filename, "rb");
235
236         face_image_h image;
237
238         int nCount = 0;
239
240         face_rect_s *rects = NULL;
241         face_component_h component;
242
243         int i;
244
245         for ( i = 0; i < TESTVIDEO_FRAME; i++)
246         {
247                 nRead = fread (YBuf, 1, nW * nH, fp );
248
249                 if ( nRead != nW * nH )
250                 {
251                         // Error
252                         tet_printf("Wanted %d bytes Read %d bytes\n", nW * nH, nRead);
253                         tet_result(TET_UNRESOLVED);
254                         return ;
255                 }
256
257                 face_image_create(FACE_IMAGE_COLORSPACE_LUMINANCE_ONLY, YBuf, nW, nH, nW * nH, &image);
258
259                 err = face_detect_faces(face, FACE_IMAGE_TYPE_CONTINIOUS, image, &rects, &nCount );
260
261                 if ( err != FACE_ERROR_NONE )
262                 {
263                         tet_printf("[F:%20s L%4d] Detect face Error! err=%d\n", __FUNCTION__, __LINE__, err);
264                         tet_result(TET_UNRESOLVED);
265                         return ;
266                 }
267
268                 if ( nCount == 0 )
269                 {
270                         continue;
271                 }
272
273                 err = face_extract_component(face, NULL, &rects[0], &component);
274
275                 dts_check_ne(szFunc, err, FACE_ERROR_NONE);
276
277                 face_image_destroy(image);
278
279                 free(rects);
280
281                 face_component_destroy(component);
282         }
283
284         err = face_destroy(face);
285
286         fclose(fp);
287 }
288
289
290 static void utc_uix_face_extract_component_negative_02(void)
291 {
292         static const char szFunc[] = "face_extract_component";
293
294         int err;
295
296         face_h face;
297
298     err = face_create(&face);
299
300         char *filename = TESTVIDEO_NAME;
301         int nW = TESTVIDEO_WIDTH;
302         int nH = TESTVIDEO_HEIGHT;
303
304         unsigned char YBuf[nW*nH];
305
306         FILE *fp;
307         int nRead;
308
309         fp = fopen(filename, "rb");
310
311         face_image_h image;
312
313         int nCount = 0;
314
315         face_rect_s *rects = NULL;
316         face_component_h component;
317
318         int i;
319
320         for ( i = 0; i < TESTVIDEO_FRAME; i++)
321         {
322                 nRead = fread (YBuf, 1, nW * nH, fp );
323
324                 if ( nRead != nW * nH )
325                 {
326                         // Error
327                         tet_printf("Wanted %d bytes Read %d bytes\n", nW * nH, nRead);
328                         tet_result(TET_UNRESOLVED);
329                         return ;
330                 }
331
332                 face_image_create(FACE_IMAGE_COLORSPACE_LUMINANCE_ONLY, YBuf, nW, nH, nW * nH, &image);
333
334                 err = face_detect_faces(face, FACE_IMAGE_TYPE_CONTINIOUS, image, &rects, &nCount );
335
336                 if ( err != FACE_ERROR_NONE )
337                 {
338                         tet_printf("[F:%20s L%4d] Detect face Error! err=%d\n", __FUNCTION__, __LINE__, err);
339                         tet_result(TET_UNRESOLVED);
340                         return ;
341                 }
342
343                 if ( nCount == 0 )
344                 {
345                         continue;
346                 }
347
348                 err = face_extract_component(face, image, NULL, &component);
349
350                 dts_check_ne(szFunc, err, FACE_ERROR_NONE);
351
352                 face_image_destroy(image);
353
354                 free(rects);
355
356                 face_component_destroy(component);
357         }
358
359         err = face_destroy(face);
360
361         fclose(fp);
362 }
363
364
365
366 static void utc_uix_face_extract_component_negative_03(void)
367 {
368         static const char szFunc[] = "face_extract_component";
369
370         int err;
371
372         face_h face;
373
374     err = face_create(&face);
375
376         char *filename = TESTVIDEO_NAME;
377         int nW = TESTVIDEO_WIDTH;
378         int nH = TESTVIDEO_HEIGHT;
379
380         unsigned char YBuf[nW*nH];
381
382         FILE *fp;
383         int nRead;
384
385         fp = fopen(filename, "rb");
386
387         face_image_h image;
388
389         int nCount = 0;
390
391         face_rect_s *rects = NULL;
392         face_component_h component;
393
394         int i;
395
396         for ( i = 0; i < TESTVIDEO_FRAME; i++)
397         {
398                 nRead = fread (YBuf, 1, nW * nH, fp );
399
400                 if ( nRead != nW * nH )
401                 {
402                         // Error
403                         tet_printf("Wanted %d bytes Read %d bytes\n", nW * nH, nRead);
404                         tet_result(TET_UNRESOLVED);
405                         return ;
406                 }
407
408                 face_image_create(FACE_IMAGE_COLORSPACE_LUMINANCE_ONLY, YBuf, nW, nH, nW * nH, &image);
409
410                 err = face_detect_faces(face, FACE_IMAGE_TYPE_CONTINIOUS, image, &rects, &nCount );
411
412                 if ( err != FACE_ERROR_NONE )
413                 {
414                         tet_printf("[F:%20s L%4d] Detect face Error! err=%d\n", __FUNCTION__, __LINE__, err);
415                         tet_result(TET_UNRESOLVED);
416                         return ;
417                 }
418
419                 if ( nCount == 0 )
420                 {
421                         continue;
422                 }
423
424                 err = face_extract_component(face, NULL, &rects[0], &component);
425
426                 dts_check_ne(szFunc, err, FACE_ERROR_NONE);
427
428                 face_image_destroy(image);
429
430                 free(rects);
431
432                 face_component_destroy(component);
433         }
434
435         err = face_destroy(face);
436
437         fclose(fp);
438 }
439
440
441 static void utc_uix_face_extract_component_negative_04(void)
442 {
443         static const char szFunc[] = "face_extract_component";
444
445         int err;
446
447         face_h face;
448
449     err = face_create(&face);
450
451         char *filename = TESTVIDEO_NAME;
452         int nW = TESTVIDEO_WIDTH;
453         int nH = TESTVIDEO_HEIGHT;
454
455         unsigned char YBuf[nW*nH];
456
457         FILE *fp;
458         int nRead;
459
460         fp = fopen(filename, "rb");
461
462         face_image_h image;
463
464         int nCount = 0;
465
466         face_rect_s *rects = NULL;
467         face_component_h component;
468
469         int i;
470
471         for ( i = 0; i < TESTVIDEO_FRAME; i++)
472         {
473                 nRead = fread (YBuf, 1, nW * nH, fp );
474
475                 if ( nRead != nW * nH )
476                 {
477                         // Error
478                         tet_printf("Wanted %d bytes Read %d bytes\n", nW * nH, nRead);
479                         tet_result(TET_UNRESOLVED);
480                         return ;
481                 }
482
483                 face_image_create(FACE_IMAGE_COLORSPACE_LUMINANCE_ONLY, YBuf, nW, nH, nW * nH, &image);
484
485                 err = face_detect_faces(face, FACE_IMAGE_TYPE_CONTINIOUS, image, &rects, &nCount );
486
487                 if ( err != FACE_ERROR_NONE )
488                 {
489                         tet_printf("[F:%20s L%4d] Detect face Error! err=%d\n", __FUNCTION__, __LINE__, err);
490                         tet_result(TET_UNRESOLVED);
491                         return ;
492                 }
493
494                 if ( nCount == 0 )
495                 {
496                         continue;
497                 }
498
499                 err = face_extract_component(face, image, &rects[0], NULL);
500
501                 dts_check_ne(szFunc, err, FACE_ERROR_NONE);
502
503                 face_image_destroy(image);
504
505                 free(rects);
506
507                 face_component_destroy(component);
508         }
509
510         err = face_destroy(face);
511
512         fclose(fp);
513 }
514
515 static void utc_uix_face_extract_feature_negative_01(void)
516 {
517         static const char szFunc[] = "face_extract_feature";
518
519         int err;
520
521         face_h face;
522
523     err = face_create(&face);
524
525         char *filename = TESTVIDEO_NAME;
526         int nW = TESTVIDEO_WIDTH;
527         int nH = TESTVIDEO_HEIGHT;
528
529         unsigned char YBuf[nW*nH];
530
531         FILE *fp;
532         int nRead;
533
534         fp = fopen(filename, "rb");
535
536         face_image_h image;
537
538         int nCount = 0;
539
540         face_rect_s *rects = NULL;
541         face_component_h component;
542         face_feature_h feature;
543
544         int i;
545
546         for ( i = 0; i < TESTVIDEO_FRAME; i++)
547         {
548                 nRead = fread (YBuf, 1, nW * nH, fp );
549
550                 if ( nRead != nW * nH )
551                 {
552                         // Error
553                         tet_printf("Wanted %d bytes Read %d bytes\n", nW * nH, nRead);
554                         tet_result(TET_UNRESOLVED);
555                         return ;
556                 }
557
558                 face_image_create(FACE_IMAGE_COLORSPACE_LUMINANCE_ONLY, YBuf, nW, nH, nW * nH, &image);
559
560                 err = face_detect_faces(face, FACE_IMAGE_TYPE_CONTINIOUS, image, &rects, &nCount );
561
562                 if ( err != FACE_ERROR_NONE )
563                 {
564                         tet_printf("[F:%20s L%4d] Detect face Error! err=%d\n", __FUNCTION__, __LINE__, err);
565                         tet_result(TET_UNRESOLVED);
566                         return ;
567                 }
568
569                 if ( nCount == 0 )
570                 {
571                         continue;
572                 }
573
574                 err = face_extract_component(face, image, &rects[0], &component);
575
576                 err = face_extract_feature(face, image, NULL, &feature);
577
578                 dts_check_ne(szFunc, err, FACE_ERROR_NONE);             // Face feature func does not support continous frame
579
580                 free(rects);
581
582                 face_image_destroy(image);
583
584                 face_component_destroy(component);
585
586                 if ( feature != NULL ) face_feature_destroy(feature);
587         }
588
589         err = face_destroy(face);
590
591         fclose(fp);
592
593 }
594
595
596 static void utc_uix_face_recognize_blink_negative_01(void)
597 {
598         static const char szFunc[] = "face_recognize_blink";
599
600         int err;
601
602         face_h face;
603
604     err = face_create(&face);
605
606         char *filename = TESTVIDEO_NAME;
607         int nW = TESTVIDEO_WIDTH;
608         int nH = TESTVIDEO_HEIGHT;
609
610         unsigned char YBuf[nW*nH];
611
612         FILE *fp;
613         int nRead;
614
615         fp = fopen(filename, "rb");
616
617         face_image_h image;
618
619         int nCount = 0;
620
621         face_rect_s *rects = NULL;
622         face_component_h component;
623         face_eye_state_e lefteye, righteye;
624
625         int i;
626
627         for ( i = 0; i < TESTVIDEO_FRAME; i++)
628         {
629                 nRead = fread (YBuf, 1, nW * nH, fp );
630
631                 if ( nRead != nW * nH )
632                 {
633                         // Error
634                         tet_printf("Wanted %d bytes Read %d bytes\n", nW * nH, nRead);
635                         tet_result(TET_UNRESOLVED);
636                         return ;
637                 }
638
639                 face_image_create(FACE_IMAGE_COLORSPACE_LUMINANCE_ONLY, YBuf, nW, nH, nW * nH, &image);
640
641                 err = face_detect_faces(face, FACE_IMAGE_TYPE_CONTINIOUS, image, &rects, &nCount );
642
643                 if ( err != FACE_ERROR_NONE )
644                 {
645                         tet_printf("[F:%20s L%4d] Detect face Error! err=%d\n", __FUNCTION__, __LINE__, err);
646                         tet_result(TET_UNRESOLVED);
647                         return ;
648                 }
649
650                 if ( nCount == 0 )
651                 {
652                         continue;
653                 }
654
655                 err = face_extract_component(face, image, &rects[0], &component);
656
657                 err = face_recognize_blink(face, NULL, component, &lefteye,  &righteye);
658
659                 dts_check_ne(szFunc, err, FACE_ERROR_NONE);
660
661                 face_image_destroy(image);
662
663                 free(rects);
664                 face_component_destroy(component);
665
666         }
667
668         err = face_destroy(face);
669
670         fclose(fp);
671
672 }
673
674 static void utc_uix_face_recognize_expression_negative_01(void)
675 {
676         static const char szFunc[] = "face_recognize_expression";
677
678         int err;
679
680         face_h face;
681
682     err = face_create(&face);
683
684         char *filename = TESTVIDEO_NAME;
685         int nW = TESTVIDEO_WIDTH;
686         int nH = TESTVIDEO_HEIGHT;
687
688         unsigned char YBuf[nW*nH];
689
690         FILE *fp;
691         int nRead;
692
693         fp = fopen(filename, "rb");
694
695         face_image_h image;
696
697         int nCount = 0;
698
699         face_rect_s *rects = NULL;
700         face_component_h component;
701         face_expression_e expr;
702
703         int i;
704
705         for ( i = 0; i < TESTVIDEO_FRAME; i++)
706         {
707                 nRead = fread (YBuf, 1, nW * nH, fp );
708
709                 if ( nRead != nW * nH )
710                 {
711                         // Error
712                         tet_printf("Wanted %d bytes Read %d bytes\n", nW * nH, nRead);
713                         tet_result(TET_UNRESOLVED);
714                         return ;
715                 }
716
717                 face_image_create(FACE_IMAGE_COLORSPACE_LUMINANCE_ONLY, YBuf, nW, nH, nW * nH, &image);
718
719                 err = face_detect_faces(face, FACE_IMAGE_TYPE_CONTINIOUS, image, &rects, &nCount );
720
721                 if ( err != FACE_ERROR_NONE )
722                 {
723                         tet_printf("[F:%20s L%4d] Detect face Error! err=%d\n", __FUNCTION__, __LINE__, err);
724                         tet_result(TET_UNRESOLVED);
725                         return ;
726                 }
727
728                 if ( nCount == 0 )
729                 {
730                         continue;
731                 }
732
733                 err = face_extract_component(face, image, &rects[0], &component);
734
735                 err = face_recognize_expression(face, image, NULL, &expr);
736
737                 dts_check_ne(szFunc, err, FACE_ERROR_NONE);
738
739                 face_image_destroy(image);
740
741                 free(rects);
742                 face_component_destroy(component);
743         }
744
745         err = face_destroy(face);
746
747         fclose(fp);
748
749 }
750
751 static void utc_uix_face_get_movement_negative_01(void)
752 {
753         static const char szFunc[] = "face_get_movement";
754
755         int err;
756
757         face_h face;
758
759     err = face_create(&face);
760
761         char *filename = TESTVIDEO_NAME;
762         int nW = TESTVIDEO_WIDTH;
763         int nH = TESTVIDEO_HEIGHT;
764
765         unsigned char YBuf[2][TESTVIDEO_WIDTH*TESTVIDEO_HEIGHT];
766
767         FILE *fp;
768         int nRead;
769
770         fp = fopen(filename, "rb");
771
772         face_image_h image;
773         face_image_h prev_image;
774
775         int nCount = 0;
776
777         face_rect_s *rects = NULL;
778
779         face_rect_s prev_rect;
780         face_rect_s cur_rect;
781
782         int i;
783
784         for ( i = 0; i < TESTVIDEO_FRAME; i++)
785         {
786                 nRead = fread (YBuf[i%2], 1, nW * nH, fp );
787
788                 if ( nRead != nW * nH )
789                 {
790                         // Error
791                         tet_printf("Wanted %d bytes Read %d bytes\n", nW * nH, nRead);
792                         tet_result(TET_UNRESOLVED);
793                         fclose(fp);
794                         return ;
795                 }
796
797                 face_image_create(FACE_IMAGE_COLORSPACE_LUMINANCE_ONLY, YBuf[i%2], nW, nH, nW * nH, &image);
798
799                 err = face_detect_faces(face, FACE_IMAGE_TYPE_CONTINIOUS, image, &rects, &nCount );
800
801                 if ( err != FACE_ERROR_NONE )
802                 {
803                         tet_printf("[F:%20s L%4d] Detect face Error! err=%d\n", __FUNCTION__, __LINE__, err);
804                         tet_result(TET_UNRESOLVED);
805                         fclose(fp);
806                         return ;
807                 }
808
809                 if ( nCount == 0 )
810                 {
811                         // rects is NULL when count is 0
812                         continue;
813                 }
814
815                 if ( i == 0 )
816                 {
817                         prev_image = image;
818                         prev_rect = rects[0];
819
820                         free(rects);
821                         continue;       // Skip first frame
822                 }
823
824                 err = face_get_movement(face, prev_image, NULL, NULL, &cur_rect);
825
826                 dts_check_ne(szFunc, err, FACE_ERROR_NONE);
827
828                 face_image_destroy(prev_image);
829
830                 prev_rect = rects[0];
831                 prev_image = image;
832
833                 free(rects);
834         }
835
836         err = face_destroy(face);
837
838         fclose(fp);
839
840 }
841
842
843 struct tet_testlist tet_testlist[] = {
844     { utc_uix_face_detect_faces_from_video_stream_negative_01, 1},
845         { utc_uix_face_detect_faces_from_video_stream_negative_02, 1},
846     { utc_uix_face_detect_faces_from_video_stream_negative_03, 1},
847     { utc_uix_face_extract_component_negative_01, 2},
848     { utc_uix_face_extract_component_negative_02, 2},
849     { utc_uix_face_extract_component_negative_03, 2},
850     { utc_uix_face_extract_component_negative_04, 2},
851     { utc_uix_face_extract_feature_negative_01, 3},
852     { utc_uix_face_recognize_blink_negative_01, 4},
853     { utc_uix_face_recognize_expression_negative_01, 5},
854         { utc_uix_face_get_movement_negative_01, 6},
855         { NULL, 0},
856 };
857