Skip to content

Commit

Permalink
Update face-detection.md and image-recognition.md
Browse files Browse the repository at this point in the history
Signed-off-by: Tae-Young Chung <[email protected]>
  • Loading branch information
tyoungroy committed Aug 1, 2018
1 parent 0fa45f6 commit bfd6b7a
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 32 deletions.
103 changes: 82 additions & 21 deletions docs/application/native/guides/multimedia/face-detection.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,38 @@ To detect faces:
```
/* For details, see the Image Util API Reference */
unsigned char *dataBuffer = NULL;
unsigned int bufferSize = 0;
int width = 0;
int height = 0;
unsigned long long bufferSize = 0;
unsigned long width = 0;
unsigned long height = 0;
image_util_decode_h imageDecoder = NULL;
error_code = image_util_decode_jpeg("/mydir/NasaAstronaut.jpg", IMAGE_UTIL_COLORSPACE_RGB888,
&dataBuffer, &height, &bufferSize);
error_code = image_util_decode_create(&imageDecoder);
if (error_code != IMAGE_UTIL_ERROR_NONE)
dlog_print(DLOG_ERROR, LOG_TAG, "error code = %d", error_code);
error_code = image_util_decode_set_input_path(imageDecoder, "/mydir/NasaAstronaut.jpg");
if (error_code != IMAGE_UTIL_ERROR_NONE)
dlog_print(DLOG_ERROR, LOG_TAG, "error code = %d", error_code);
error_code = image_util_decode_set_colorspace(imageDecoder, IMAGE_UTIL_COLORSPACE_RGB888);
if (error_code != IMAGE_UTIL_ERROR_NONE)
dlog_print(DLOG_ERROR, LOG_TAG, "error code = %d", error_code);
error_code = image_util_decode_set_output_buffer(imageDecoder, &dataBuffer);
if (error_code != IMAGE_UTIL_ERROR_NONE)
dlog_print(DLOG_ERROR, LOG_TAG, "error code = %d", error_code);
error_code = image_util_decode_run(imageDecoder, &width, &height, &bufferSize);
if (error_code != IMAGE_UTIL_ERROR_NONE)
dlog_print(DLOG_ERROR, LOG_TAG, "error code = %d", error_code);
error_code = image_util_decode_destroy(imageDecoder);
if (error_code != IMAGE_UTIL_ERROR_NONE)
dlog_print(DLOG_ERROR, LOG_TAG, "error code = %d", error_code);
/* Fill the dataBuffer to g_source */
error_code = mv_source_fill_by_buffer(facedata.g_source, dataBuffer, bufferSize,
width, height, MEDIA_VISION_COLORSPACE_RGB888);
error_code = mv_source_fill_by_buffer(facedata.g_source, dataBuffer, (unsigned int)bufferSize,
(unsigned int)width, (unsigned int)height, MEDIA_VISION_COLORSPACE_RGB888);
if (error_code != MEDIA_VISION_ERROR_NONE)
dlog_print(DLOG_ERROR, LOG_TAG, "error code = %d", error_code);
Expand Down Expand Up @@ -221,16 +241,32 @@ To recognize faces:

char filePath[1024];
unsigned char *dataBuffer = NULL;
unsigned int bufferSize = 0;
int width = 0;
int height = 0;
unsigned long long bufferSize = 0;
unsigned long width = 0;
unsigned long height = 0;
image_util_decode_h imageDecoder = NULL;

error_code = image_util_decode_create(&imageDecoder);
if (error_code != IMAGE_UTIL_ERROR_NONE)
dlog_print(DLOG_ERROR, LOG_TAG, "error code = %d", error_code);

error_code = image_util_decode_set_colorspace(imageDecoder, IMAGE_UTIL_COLORSPACE_RGB888);
if (error_code != IMAGE_UTIL_ERROR_NONE)
dlog_print(DLOG_ERROR, LOG_TAG, "error code = %d", error_code);

for (example_index = 1; example_index <= 10; ++example_index) {
/* Decode image and fill the image data to g_source handle */
snprintf(filePath, 1024, "%s/face_sample_%d.jpg", mydir, example_index);
error_code = image_util_decode_jpeg(filePath, IMAGE_UTIL_COLORSPACE_RGB888,
&dataBuffer, &width, &height, &bufferSize);
if (error_code != MEDIA_VISION_ERROR_NONE)
error_code = image_util_decode_set_input_path(imageDecoder, filePath);
if (error_code != IMAGE_UTIL_ERROR_NONE)
dlog_print(DLOG_ERROR, LOG_TAG, "error code = %d", error_code);

error_code = image_util_decode_set_output_buffer(imageDecoder, &dataBuffer);
if (error_code != IMAGE_UTIL_ERROR_NONE)
dlog_print(DLOG_ERROR, LOG_TAG, "error code = %d", error_code);

error_code = image_util_decode_run(imageDecoder, &width, &height, &bufferSize);
if (error_code != IMAGE_UTIL_ERROR_NONE)
dlog_print(DLOG_ERROR, LOG_TAG, "error code = %d", error_code);

roi.x = roi.y = 0;
Expand All @@ -240,8 +276,8 @@ To recognize faces:
if (error_code != MEDIA_VISION_ERROR_NONE)
dlog_print(DLOG_ERROR, LOG_TAG, "error code = %d", error_code);

error_code = mv_source_fill_by_buffer(facedata.g_source, &dataBuffer,
&bufferSize, &width, &height, MEDIA_VISION_COLORSPACE_RGB888);
error_code = mv_source_fill_by_buffer(facedata.g_source, dataBuffer, (unsigned int)bufferSize,
(unsigned int)width, (unsigned int)height, MEDIA_VISION_COLORSPACE_RGB888);
if (error_code != MEDIA_VISION_ERROR_NONE)
dlog_print(DLOG_ERROR, LOG_TAG, "error code = %d", error_code);

Expand All @@ -253,6 +289,10 @@ To recognize faces:
if (error_code != MEDIA_VISION_ERROR_NONE)
dlog_print(DLOG_ERROR, LOG_TAG, "error code = %d", error_code);
}

error_code = image_util_decode_destroy(imageDecoder);
if (error_code != IMAGE_UTIL_ERROR_NONE)
dlog_print(DLOG_ERROR, LOG_TAG, "error code = %d", error_code);
```
4. Use the `mv_face_recognition_model_learn()` function to train the face recognition model with the added examples:
Expand All @@ -271,17 +311,38 @@ To recognize faces:
```
/* Decode the image and fill the image data to g_source handle */
snprintf(filePath, 1024, "%s/whos_face.jpg", mydir);
error_code = image_util_decode_jpeg(filePath, IMAGE_UTIL_COLORSPACE_RGB888,
&dataBuffer, &width, &height, &bufferSize);
if (error_code != MEDIA_VISION_ERROR_NONE)
dlog_print(DLOG_ERROR, LOG_TAG, "error code= %d", error_code);
image_util_decode_h imageDecoder = NULL;
error_code = image_util_decode_create(&imageDecoder);
if (error_code != IMAGE_UTIL_ERROR_NONE)
dlog_print(DLOG_ERROR, LOG_TAG, "error code = %d", error_code);
error_code = image_util_decode_set_input_path(imageDecoder, filePath);
if (error_code != IMAGE_UTIL_ERROR_NONE)
dlog_print(DLOG_ERROR, LOG_TAG, "error code = %d", error_code);
error_code = image_util_decode_set_colorspace(imageDecoder, IMAGE_UTIL_COLORSPACE_RGB888);
if (error_code != IMAGE_UTIL_ERROR_NONE)
dlog_print(DLOG_ERROR, LOG_TAG, "error code = %d", error_code);
error_code = image_util_decode_set_output_buffer(imageDecoder, &dataBuffer);
if (error_code != IMAGE_UTIL_ERROR_NONE)
dlog_print(DLOG_ERROR, LOG_TAG, "error code = %d", error_code);
error_code = image_util_decode_run(imageDecoder, &width, &height, &bufferSize);
if (error_code != IMAGE_UTIL_ERROR_NONE)
dlog_print(DLOG_ERROR, LOG_TAG, "error code = %d", error_code);
error_code = image_util_decode_destroy(imageDecoder);
if (error_code != IMAGE_UTIL_ERROR_NONE)
dlog_print(DLOG_ERROR, LOG_TAG, "error code = %d", error_code);
error_code = mv_source_clear(facedata.g_source);
if (error_code != MEDIA_VISION_ERROR_NONE)
dlog_print(DLOG_ERROR, LOG_TAG, "error code= %d", error_code);
error_code = mv_source_fill_by_buffer(facedata.g_source, &dataBuffer, &bufferSize,
&width, &height, MEDIA_VISION_COLORSPACE_RGB888);
error_code = mv_source_fill_by_buffer(facedata.g_source, dataBuffer, (unsigned int)bufferSize,
(unsigned int)width, (unsigned int)height, MEDIA_VISION_COLORSPACE_RGB888);
if (error_code != MEDIA_VISION_ERROR_NONE)
dlog_print(DLOG_ERROR, LOG_TAG, "error code= %d", error_code);
Expand Down
61 changes: 50 additions & 11 deletions docs/application/native/guides/multimedia/image-recognition.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,38 @@ To recognize images:
```
/* For details, see the Image Util API Reference */
unsigned char *dataBuffer = NULL;
unsigned int bufferSize = 0;
int width = 0;
int height = 0;
unsigned long long bufferSize = 0;
unsigned long width = 0;
unsigned long height = 0;
image_util_decode_h imageDecoder = NULL;
error_code = image_util_decode_jpeg("/mydir/sample.jpg", IMAGE_UTIL_COLORSPACE_RGB888,
&dataBuffer, &width, &height, &bufferSize);
error_code = image_util_decode_create(&imageDecoder);
if (error_code != IMAGE_UTIL_ERROR_NONE)
dlog_print(DLOG_ERROR, LOG_TAG, "error code = %d", error_code);
error_code = image_util_decode_set_input_path(imageDecoder, "/mydir/sample.jpg");
if (error_code != IMAGE_UTIL_ERROR_NONE)
dlog_print(DLOG_ERROR, LOG_TAG, "error code = %d", error_code);
error_code = image_util_decode_set_colorspace(imageDecoder, IMAGE_UTIL_COLORSPACE_RGB888);
if (error_code != IMAGE_UTIL_ERROR_NONE)
dlog_print(DLOG_ERROR, LOG_TAG, "error code = %d", error_code);
error_code = image_util_decode_set_output_buffer(imageDecoder, &dataBuffer);
if (error_code != IMAGE_UTIL_ERROR_NONE)
dlog_print(DLOG_ERROR, LOG_TAG, "error code = %d", error_code);
error_code = image_util_decode_run(imageDecoder, &width, &height, &bufferSize);
if (error_code != IMAGE_UTIL_ERROR_NONE)
dlog_print(DLOG_ERROR, LOG_TAG, "error code = %d", error_code);
error_code = image_util_decode_destroy(imageDecoder);
if (error_code != IMAGE_UTIL_ERROR_NONE)
dlog_print(DLOG_ERROR, LOG_TAG, "error code = %d", error_code);
/* Fill the dataBuffer to g_source */
error_code = mv_source_fill_by_buffer(imagedata.g_source, dataBuffer, bufferSize,
width, height, MEDIA_VISION_COLORSPACE_RGB888);
error_code = mv_source_fill_by_buffer(imagedata.g_source, dataBuffer, (unsigned int)bufferSize,
(unsigned int)width, (unsigned int)height, MEDIA_VISION_COLORSPACE_RGB888);
if (error_code != MEDIA_VISION_ERROR_NONE)
dlog_print(DLOG_ERROR, LOG_TAG, "error code = %d", error_code);
Expand Down Expand Up @@ -143,8 +163,27 @@ To recognize images:
The following example assumes that there is a `what_isThis.jpg` image file in the `<OwnDataPath>` folder, including the image object.
```
error_code = image_util_decode_jpeg("/mydir/what_isThis.jpg", IMAGE_UTIL_COLORSPACE_RGB888,
&dataBuffer, &width, &height, &bufferSize);
error_code = image_util_decode_create(&imageDecoder);
if (error_code != IMAGE_UTIL_ERROR_NONE)
dlog_print(DLOG_ERROR, LOG_TAG, "error code = %d", error_code);
error_code = image_util_decode_set_input_path(imageDecoder, "/mydir/what_isThis.jpg");
if (error_code != IMAGE_UTIL_ERROR_NONE)
dlog_print(DLOG_ERROR, LOG_TAG, "error code = %d", error_code);
error_code = image_util_decode_set_colorspace(imageDecoder, IMAGE_UTIL_COLORSPACE_RGB888);
if (error_code != IMAGE_UTIL_ERROR_NONE)
dlog_print(DLOG_ERROR, LOG_TAG, "error code = %d", error_code);
error_code = image_util_decode_set_output_buffer(imageDecoder, &dataBuffer);
if (error_code != IMAGE_UTIL_ERROR_NONE)
dlog_print(DLOG_ERROR, LOG_TAG, "error code = %d", error_code);
error_code = image_util_decode_run(imageDecoder, &width, &height, &bufferSize);
if (error_code != IMAGE_UTIL_ERROR_NONE)
dlog_print(DLOG_ERROR, LOG_TAG, "error code = %d", error_code);
error_code = image_util_decode_destroy(imageDecoder);
if (error_code != IMAGE_UTIL_ERROR_NONE)
dlog_print(DLOG_ERROR, LOG_TAG, "error code = %d", error_code);
Expand All @@ -153,8 +192,8 @@ To recognize images:
dlog_print(DLOG_ERROR, LOG_TAG, "error code = %d", error_code);
/* Fill the dataBuffer to g_source */
error_code = mv_source_fill_by_buffer(imagedata.g_source, dataBuffer, bufferSize,
width, height, MEDIA_VISION_COLORSPACE_RGB888);
error_code = mv_source_fill_by_buffer(imagedata.g_source, dataBuffer, (unsigned int)bufferSize,
(unsigned int)width, (unsigned int)height, MEDIA_VISION_COLORSPACE_RGB888);
if (error_code != MEDIA_VISION_ERROR_NONE)
dlog_print(DLOG_ERROR, LOG_TAG, "error code = %d", error_code);
Expand Down

0 comments on commit bfd6b7a

Please sign in to comment.