/* * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include #include #include static void startup(void); static void cleanup(void); void (*tet_startup)(void) = startup; void (*tet_cleanup)(void) = cleanup; #define TESTVIDEO_NAME (DATADIR"suzie_qcif.yuv") #define TESTVIDEO_WIDTH (176) #define TESTVIDEO_HEIGHT (144) #define TESTVIDEO_FRAME (10) static void startup(void) { // TODO : How to copy sample image???? } static void cleanup(void) { /* end of TC */ } static void utc_uix_face_detect_faces_from_video_stream_negative_01(void) { static const char szFunc[] = "face_detect_faces_from_video_stream"; int err; face_h face; err = face_create(&face); char *filename = TESTVIDEO_NAME; int nW = TESTVIDEO_WIDTH; int nH = TESTVIDEO_HEIGHT; unsigned char YBuf[nW*nH]; FILE *fp; int nRead; fp = fopen(filename, "rb"); if ( fp == NULL ) { tet_printf("Cannot load file. %s", filename); tet_result(TET_UNRESOLVED); return; } face_image_h image; int nCount = 0; face_rect_s *rects = NULL; int i; for ( i = 0; i < TESTVIDEO_FRAME; i++) { nRead = fread (YBuf, 1, nW * nH, fp ); if ( nRead != nW * nH ) { // Error tet_printf("Wanted %d bytes Read %d bytes\n", nW * nH, nRead); tet_result(TET_UNRESOLVED); return ; } face_image_create(FACE_IMAGE_COLORSPACE_LUMINANCE_ONLY, YBuf, nW, nH, nW * nH, &image); err = face_detect_faces(face, FACE_IMAGE_TYPE_CONTINIOUS, image, NULL, &nCount ); dts_check_ne(szFunc, err, FACE_ERROR_NONE); face_image_destroy(image); } err = face_destroy(face); fclose(fp); } static void utc_uix_face_detect_faces_from_video_stream_negative_02(void) { static const char szFunc[] = "face_detect_faces_from_video_stream"; int err; face_h face; err = face_create(&face); char *filename = TESTVIDEO_NAME; int nW = TESTVIDEO_WIDTH; int nH = TESTVIDEO_HEIGHT; unsigned char YBuf[nW*nH]; FILE *fp; int nRead; fp = fopen(filename, "rb"); if ( fp == NULL ) { tet_printf("Cannot load file. %s", filename); tet_result(TET_UNRESOLVED); return; } face_image_h image; int nCount = 0; face_rect_s *rects = NULL; int i; for ( i = 0; i < TESTVIDEO_FRAME; i++) { nRead = fread (YBuf, 1, nW * nH, fp ); if ( nRead != nW * nH ) { // Error tet_printf("Wanted %d bytes Read %d bytes\n", nW * nH, nRead); tet_result(TET_UNRESOLVED); return ; } face_image_create(FACE_IMAGE_COLORSPACE_LUMINANCE_ONLY, YBuf, nW, nH, nW * nH, &image); err = face_detect_faces(face, FACE_IMAGE_TYPE_CONTINIOUS, image, &rects, NULL ); dts_check_ne(szFunc, err, FACE_ERROR_NONE); face_image_destroy(image); } err = face_destroy(face); fclose(fp); } static void utc_uix_face_detect_faces_from_video_stream_negative_03(void) { static const char szFunc[] = "face_detect_faces_from_video_stream"; int err; face_h face; err = face_create(&face); char *filename = TESTVIDEO_NAME; int nW = TESTVIDEO_WIDTH; int nH = TESTVIDEO_HEIGHT; unsigned char YBuf[nW*nH]; FILE *fp; int nRead; fp = fopen(filename, "rb"); if ( fp == NULL ) { tet_printf("Cannot load file. %s", filename); tet_result(TET_UNRESOLVED); return; } face_image_h image; int nCount = 0; face_rect_s *rects = NULL; int i; for ( i = 0; i < TESTVIDEO_FRAME; i++) { nRead = fread (YBuf, 1, nW * nH, fp ); if ( nRead != nW * nH ) { // Error tet_printf("Wanted %d bytes Read %d bytes\n", nW * nH, nRead); tet_result(TET_UNRESOLVED); return ; } face_image_create(FACE_IMAGE_COLORSPACE_LUMINANCE_ONLY, YBuf, nW, nH, nW * nH, &image); err = face_detect_faces(face, FACE_IMAGE_TYPE_CONTINIOUS, NULL, &rects, &nCount ); dts_check_ne(szFunc, err, FACE_ERROR_NONE); face_image_destroy(image); } err = face_destroy(face); fclose(fp); } static void utc_uix_face_extract_component_negative_01(void) { static const char szFunc[] = "face_extract_component"; int err; face_h face; err = face_create(&face); char *filename = TESTVIDEO_NAME; int nW = TESTVIDEO_WIDTH; int nH = TESTVIDEO_HEIGHT; unsigned char YBuf[nW*nH]; FILE *fp; int nRead; fp = fopen(filename, "rb"); if ( fp == NULL ) { tet_printf("Cannot load file. %s", filename); tet_result(TET_UNRESOLVED); return; } face_image_h image; int nCount = 0; face_rect_s *rects = NULL; face_component_h component; int i; for ( i = 0; i < TESTVIDEO_FRAME; i++) { nRead = fread (YBuf, 1, nW * nH, fp ); if ( nRead != nW * nH ) { // Error tet_printf("Wanted %d bytes Read %d bytes\n", nW * nH, nRead); tet_result(TET_UNRESOLVED); return ; } face_image_create(FACE_IMAGE_COLORSPACE_LUMINANCE_ONLY, YBuf, nW, nH, nW * nH, &image); err = face_detect_faces(face, FACE_IMAGE_TYPE_CONTINIOUS, image, &rects, &nCount ); if ( err != FACE_ERROR_NONE ) { tet_printf("[F:%20s L%4d] Detect face Error! err=%d\n", __FUNCTION__, __LINE__, err); tet_result(TET_UNRESOLVED); return ; } if ( nCount == 0 ) { continue; } err = face_extract_component(face, NULL, &rects[0], &component); dts_check_ne(szFunc, err, FACE_ERROR_NONE); face_image_destroy(image); free(rects); face_component_destroy(component); } err = face_destroy(face); fclose(fp); } static void utc_uix_face_extract_component_negative_02(void) { static const char szFunc[] = "face_extract_component"; int err; face_h face; err = face_create(&face); char *filename = TESTVIDEO_NAME; int nW = TESTVIDEO_WIDTH; int nH = TESTVIDEO_HEIGHT; unsigned char YBuf[nW*nH]; FILE *fp; int nRead; fp = fopen(filename, "rb"); if ( fp == NULL ) { tet_printf("Cannot load file. %s", filename); tet_result(TET_UNRESOLVED); return; } face_image_h image; int nCount = 0; face_rect_s *rects = NULL; face_component_h component; int i; for ( i = 0; i < TESTVIDEO_FRAME; i++) { nRead = fread (YBuf, 1, nW * nH, fp ); if ( nRead != nW * nH ) { // Error tet_printf("Wanted %d bytes Read %d bytes\n", nW * nH, nRead); tet_result(TET_UNRESOLVED); return ; } face_image_create(FACE_IMAGE_COLORSPACE_LUMINANCE_ONLY, YBuf, nW, nH, nW * nH, &image); err = face_detect_faces(face, FACE_IMAGE_TYPE_CONTINIOUS, image, &rects, &nCount ); if ( err != FACE_ERROR_NONE ) { tet_printf("[F:%20s L%4d] Detect face Error! err=%d\n", __FUNCTION__, __LINE__, err); tet_result(TET_UNRESOLVED); return ; } if ( nCount == 0 ) { continue; } err = face_extract_component(face, image, NULL, &component); dts_check_ne(szFunc, err, FACE_ERROR_NONE); face_image_destroy(image); free(rects); face_component_destroy(component); } err = face_destroy(face); fclose(fp); } static void utc_uix_face_extract_component_negative_03(void) { static const char szFunc[] = "face_extract_component"; int err; face_h face; err = face_create(&face); char *filename = TESTVIDEO_NAME; int nW = TESTVIDEO_WIDTH; int nH = TESTVIDEO_HEIGHT; unsigned char YBuf[nW*nH]; FILE *fp; int nRead; fp = fopen(filename, "rb"); if ( fp == NULL ) { tet_printf("Cannot load file. %s", filename); tet_result(TET_UNRESOLVED); return; } face_image_h image; int nCount = 0; face_rect_s *rects = NULL; face_component_h component; int i; for ( i = 0; i < TESTVIDEO_FRAME; i++) { nRead = fread (YBuf, 1, nW * nH, fp ); if ( nRead != nW * nH ) { // Error tet_printf("Wanted %d bytes Read %d bytes\n", nW * nH, nRead); tet_result(TET_UNRESOLVED); return ; } face_image_create(FACE_IMAGE_COLORSPACE_LUMINANCE_ONLY, YBuf, nW, nH, nW * nH, &image); err = face_detect_faces(face, FACE_IMAGE_TYPE_CONTINIOUS, image, &rects, &nCount ); if ( err != FACE_ERROR_NONE ) { tet_printf("[F:%20s L%4d] Detect face Error! err=%d\n", __FUNCTION__, __LINE__, err); tet_result(TET_UNRESOLVED); return ; } if ( nCount == 0 ) { continue; } err = face_extract_component(face, NULL, &rects[0], &component); dts_check_ne(szFunc, err, FACE_ERROR_NONE); face_image_destroy(image); free(rects); face_component_destroy(component); } err = face_destroy(face); fclose(fp); } static void utc_uix_face_extract_component_negative_04(void) { static const char szFunc[] = "face_extract_component"; int err; face_h face; err = face_create(&face); char *filename = TESTVIDEO_NAME; int nW = TESTVIDEO_WIDTH; int nH = TESTVIDEO_HEIGHT; unsigned char YBuf[nW*nH]; FILE *fp; int nRead; fp = fopen(filename, "rb"); if ( fp == NULL ) { tet_printf("Cannot load file. %s", filename); tet_result(TET_UNRESOLVED); return; } face_image_h image; int nCount = 0; face_rect_s *rects = NULL; face_component_h component; int i; for ( i = 0; i < TESTVIDEO_FRAME; i++) { nRead = fread (YBuf, 1, nW * nH, fp ); if ( nRead != nW * nH ) { // Error tet_printf("Wanted %d bytes Read %d bytes\n", nW * nH, nRead); tet_result(TET_UNRESOLVED); return ; } face_image_create(FACE_IMAGE_COLORSPACE_LUMINANCE_ONLY, YBuf, nW, nH, nW * nH, &image); err = face_detect_faces(face, FACE_IMAGE_TYPE_CONTINIOUS, image, &rects, &nCount ); if ( err != FACE_ERROR_NONE ) { tet_printf("[F:%20s L%4d] Detect face Error! err=%d\n", __FUNCTION__, __LINE__, err); tet_result(TET_UNRESOLVED); return ; } if ( nCount == 0 ) { continue; } err = face_extract_component(face, image, &rects[0], NULL); dts_check_ne(szFunc, err, FACE_ERROR_NONE); face_image_destroy(image); free(rects); face_component_destroy(component); } err = face_destroy(face); fclose(fp); } static void utc_uix_face_extract_feature_negative_01(void) { static const char szFunc[] = "face_extract_feature"; int err; face_h face; err = face_create(&face); char *filename = TESTVIDEO_NAME; int nW = TESTVIDEO_WIDTH; int nH = TESTVIDEO_HEIGHT; unsigned char YBuf[nW*nH]; FILE *fp; int nRead; fp = fopen(filename, "rb"); if ( fp == NULL ) { tet_printf("Cannot load file. %s", filename); tet_result(TET_UNRESOLVED); return; } face_image_h image; int nCount = 0; face_rect_s *rects = NULL; face_component_h component; face_feature_h feature; int i; for ( i = 0; i < TESTVIDEO_FRAME; i++) { nRead = fread (YBuf, 1, nW * nH, fp ); if ( nRead != nW * nH ) { // Error tet_printf("Wanted %d bytes Read %d bytes\n", nW * nH, nRead); tet_result(TET_UNRESOLVED); return ; } face_image_create(FACE_IMAGE_COLORSPACE_LUMINANCE_ONLY, YBuf, nW, nH, nW * nH, &image); err = face_detect_faces(face, FACE_IMAGE_TYPE_CONTINIOUS, image, &rects, &nCount ); if ( err != FACE_ERROR_NONE ) { tet_printf("[F:%20s L%4d] Detect face Error! err=%d\n", __FUNCTION__, __LINE__, err); tet_result(TET_UNRESOLVED); return ; } if ( nCount == 0 ) { continue; } err = face_extract_component(face, image, &rects[0], &component); err = face_extract_feature(face, image, NULL, &feature); dts_check_ne(szFunc, err, FACE_ERROR_NONE); // Face feature func does not support continous frame free(rects); face_image_destroy(image); face_component_destroy(component); if ( feature != NULL ) face_feature_destroy(feature); } err = face_destroy(face); fclose(fp); } static void utc_uix_face_recognize_blink_negative_01(void) { static const char szFunc[] = "face_recognize_blink"; int err; face_h face; err = face_create(&face); char *filename = TESTVIDEO_NAME; int nW = TESTVIDEO_WIDTH; int nH = TESTVIDEO_HEIGHT; unsigned char YBuf[nW*nH]; FILE *fp; int nRead; fp = fopen(filename, "rb"); if ( fp == NULL ) { tet_printf("Cannot load file. %s", filename); tet_result(TET_UNRESOLVED); return; } face_image_h image; int nCount = 0; face_rect_s *rects = NULL; face_component_h component; face_eye_state_e lefteye, righteye; int i; for ( i = 0; i < TESTVIDEO_FRAME; i++) { nRead = fread (YBuf, 1, nW * nH, fp ); if ( nRead != nW * nH ) { // Error tet_printf("Wanted %d bytes Read %d bytes\n", nW * nH, nRead); tet_result(TET_UNRESOLVED); return ; } face_image_create(FACE_IMAGE_COLORSPACE_LUMINANCE_ONLY, YBuf, nW, nH, nW * nH, &image); err = face_detect_faces(face, FACE_IMAGE_TYPE_CONTINIOUS, image, &rects, &nCount ); if ( err != FACE_ERROR_NONE ) { tet_printf("[F:%20s L%4d] Detect face Error! err=%d\n", __FUNCTION__, __LINE__, err); tet_result(TET_UNRESOLVED); return ; } if ( nCount == 0 ) { continue; } err = face_extract_component(face, image, &rects[0], &component); err = face_recognize_blink(face, NULL, component, &lefteye, &righteye); dts_check_ne(szFunc, err, FACE_ERROR_NONE); face_image_destroy(image); free(rects); face_component_destroy(component); } err = face_destroy(face); fclose(fp); } static void utc_uix_face_recognize_expression_negative_01(void) { static const char szFunc[] = "face_recognize_expression"; int err; face_h face; err = face_create(&face); char *filename = TESTVIDEO_NAME; int nW = TESTVIDEO_WIDTH; int nH = TESTVIDEO_HEIGHT; unsigned char YBuf[nW*nH]; FILE *fp; int nRead; fp = fopen(filename, "rb"); if ( fp == NULL ) { tet_printf("Cannot load file. %s", filename); tet_result(TET_UNRESOLVED); return; } face_image_h image; int nCount = 0; face_rect_s *rects = NULL; face_component_h component; face_expression_e expr; int i; for ( i = 0; i < TESTVIDEO_FRAME; i++) { nRead = fread (YBuf, 1, nW * nH, fp ); if ( nRead != nW * nH ) { // Error tet_printf("Wanted %d bytes Read %d bytes\n", nW * nH, nRead); tet_result(TET_UNRESOLVED); return ; } face_image_create(FACE_IMAGE_COLORSPACE_LUMINANCE_ONLY, YBuf, nW, nH, nW * nH, &image); err = face_detect_faces(face, FACE_IMAGE_TYPE_CONTINIOUS, image, &rects, &nCount ); if ( err != FACE_ERROR_NONE ) { tet_printf("[F:%20s L%4d] Detect face Error! err=%d\n", __FUNCTION__, __LINE__, err); tet_result(TET_UNRESOLVED); return ; } if ( nCount == 0 ) { continue; } err = face_extract_component(face, image, &rects[0], &component); err = face_recognize_expression(face, image, NULL, &expr); dts_check_ne(szFunc, err, FACE_ERROR_NONE); face_image_destroy(image); free(rects); face_component_destroy(component); } err = face_destroy(face); fclose(fp); } static void utc_uix_face_get_movement_negative_01(void) { static const char szFunc[] = "face_get_movement"; int err; face_h face; err = face_create(&face); char *filename = TESTVIDEO_NAME; int nW = TESTVIDEO_WIDTH; int nH = TESTVIDEO_HEIGHT; unsigned char YBuf[2][TESTVIDEO_WIDTH*TESTVIDEO_HEIGHT]; FILE *fp; int nRead; fp = fopen(filename, "rb"); if ( fp == NULL ) { tet_printf("Cannot load file. %s", filename); tet_result(TET_UNRESOLVED); return; } face_image_h image; face_image_h prev_image; int nCount = 0; face_rect_s *rects = NULL; face_rect_s prev_rect; face_rect_s cur_rect; int i; for ( i = 0; i < TESTVIDEO_FRAME; i++) { nRead = fread (YBuf[i%2], 1, nW * nH, fp ); if ( nRead != nW * nH ) { // Error tet_printf("Wanted %d bytes Read %d bytes\n", nW * nH, nRead); tet_result(TET_UNRESOLVED); fclose(fp); return ; } face_image_create(FACE_IMAGE_COLORSPACE_LUMINANCE_ONLY, YBuf[i%2], nW, nH, nW * nH, &image); err = face_detect_faces(face, FACE_IMAGE_TYPE_CONTINIOUS, image, &rects, &nCount ); if ( err != FACE_ERROR_NONE ) { tet_printf("[F:%20s L%4d] Detect face Error! err=%d\n", __FUNCTION__, __LINE__, err); tet_result(TET_UNRESOLVED); fclose(fp); return ; } if ( nCount == 0 ) { // rects is NULL when count is 0 continue; } if ( i == 0 ) { prev_image = image; prev_rect = rects[0]; free(rects); continue; // Skip first frame } err = face_get_movement(face, prev_image, NULL, NULL, &cur_rect); dts_check_ne(szFunc, err, FACE_ERROR_NONE); face_image_destroy(prev_image); prev_rect = rects[0]; prev_image = image; free(rects); } err = face_destroy(face); fclose(fp); } struct tet_testlist tet_testlist[] = { { utc_uix_face_detect_faces_from_video_stream_negative_01, 1}, { utc_uix_face_detect_faces_from_video_stream_negative_02, 1}, { utc_uix_face_detect_faces_from_video_stream_negative_03, 1}, { utc_uix_face_extract_component_negative_01, 2}, { utc_uix_face_extract_component_negative_02, 2}, { utc_uix_face_extract_component_negative_03, 2}, { utc_uix_face_extract_component_negative_04, 2}, { utc_uix_face_extract_feature_negative_01, 3}, { utc_uix_face_recognize_blink_negative_01, 4}, { utc_uix_face_recognize_expression_negative_01, 5}, { utc_uix_face_get_movement_negative_01, 6}, { NULL, 0}, };