You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2021/09/16 06:51:03 UTC

[GitHub] [incubator-nuttx-apps] jerpelea commented on a change in pull request #851: examples/camera: Fix some issues and update license

jerpelea commented on a change in pull request #851:
URL: https://github.com/apache/incubator-nuttx-apps/pull/851#discussion_r709827465



##########
File path: examples/camera/camera_main.c
##########
@@ -525,74 +536,182 @@ int main(int argc, FAR char *argv[])
    * order from the captured frame buffer and a new camera image is
    * recaptured.
    *
-   * Allocate freame buffers for QVGA YUV422 size (320x240x2=150KB).
+   * Allocate freame buffers for QVGA RGB565 size (320x240x2=150KB).
    * Number of frame buffers is defined as VIDEO_BUFNUM(3).
    * And all allocated memorys are VIDIOC_QBUFed.
    */
 
   ret = camera_prepare(v_fd, V4L2_BUF_TYPE_VIDEO_CAPTURE,
-                       V4L2_BUF_MODE_RING, V4L2_PIX_FMT_UYVY,
+                       V4L2_BUF_MODE_RING, V4L2_PIX_FMT_RGB565,
                        VIDEO_HSIZE_QVGA, VIDEO_VSIZE_QVGA,
-                       &buffers_video, VIDEO_BUFNUM, IMAGE_YUV_SIZE);
+                       &buffers_video, VIDEO_BUFNUM, IMAGE_RGB_SIZE);
   if (ret != OK)
     {
       goto exit_this_app;
     }
 
-  printf("Take %d pictures as %s file in %s after %d mili-seconds.\n",
-         capture_num,
-         (capture_type == V4L2_BUF_TYPE_STILL_CAPTURE) ? "JPEG" : "YUV",
-         save_dir, START_CAPTURE_TIME);
-  printf(" After taking pictures, the app will be exit after %d ms.\n",
-      KEEP_VIDEO_TIME);
+  /* This application has 3 states.
+   *
+   * APP_STATE_BEFORE_CAPTURE:
+   *    This state waits 5 seconds (definded START_CAPTURE_TIME)
+   *    with displaying preview (VIDEO_CAPTURE stream image) on LCD.
+   *    After 5 seconds, state will be changed to APP_STATE_UNDER_CAPTURE.
+   *
+   * APP_STATE_UNDER_CAPTURE:
+   *    This state will start taking picture and store the image into files.
+   *    Number of taking pictures is set capture_num valiable.
+   *    It can be changed by command line argument.
+   *    After finishing taking pictures, the state will be changed to
+   *    APP_STATE_AFTER_CAPTURE.
+   *
+   * APP_STATE_AFTER_CAPTURE:
+   *    This state waits 10 seconds (definded KEEP_VIDEO_TIME)
+   *    with displaying preview (VIDEO_CAPTURE stream image) on LCD.
+   *    After 10 seconds, this application will be finished.
+   *
+   * Notice:
+   *    If capture_num is set '0', state will stay APP_STATE_BEFORE_CAPTURE.
+   */
 
-  RESET_INITIAL_TIME(then);
+  app_state = APP_STATE_BEFORE_CAPTURE;
 
-  /* =====  Main Loop  ===== */
+  /* Show this application behavior. */
 
-  while (1)
+  if (capture_num == 0)
     {
-      printf("Start capturing...\n");
-      ret = start_stillcapture(v_fd, capture_type);
-      if (ret != OK)
-        {
-          goto exit_this_app;
-        }
-
-      while (capture_num)
-        {
-          ret = get_camimage(v_fd, &v4l2_buf, capture_type);
-          if (ret != OK)
-            {
-              goto exit_this_app;
-            }
-
-          futil_writeimage((uint8_t *)v4l2_buf.m.userptr,
-           (size_t)v4l2_buf.bytesused,
-           (capture_type == V4L2_BUF_TYPE_VIDEO_CAPTURE) ? "YUV" : "JPG");
+      is_eternal = 1;
+      printf("Start video this mode is eternal."
+             " (Non stop, non save files.)\n");
+#ifndef CONFIG_EXAMPLES_CAMERA_OUTPUT_LCD
+      printf("This mode should be run with LCD display\n");
+#endif
+    }
+  else
+    {
+      is_eternal = 0;
+      wait.tv_sec = START_CAPTURE_TIME;
+      wait.tv_usec = 0;
+      printf("Take %d pictures as %s file in %s after %d seconds.\n",
+             capture_num,
+              (capture_type == V4L2_BUF_TYPE_STILL_CAPTURE) ? "JPEG" : "RGB",
+             save_dir, START_CAPTURE_TIME);
+      printf(" After finishing taking pictures,"
+             " this app will be finished after %d seconds.\n",
+              KEEP_VIDEO_TIME);
+    }
 
-          ret = release_camimage(v_fd, &v4l2_buf);
-          if (ret != OK)
-            {
-              goto exit_this_app;
-            }
+  gettimeofday(&start, NULL);
 
-          capture_num--;
-        }
+  /* =====  Main Loop  ===== */
 
-      ret = stop_stillcapture(v_fd, capture_type);
-      if (ret != OK)
+  while (1)
+    {
+      switch (app_state)
         {
-          goto exit_this_app;
+          /* BEFORE_CAPTURE and AFTER_CAPTURE is waiting for expiring the
+           * time.
+           * In the meantime, Captureing VIDEO image to show pre-view on LCD.
+           */
+
+          case APP_STATE_BEFORE_CAPTURE:
+          case APP_STATE_AFTER_CAPTURE:
+            ret = get_camimage(v_fd, &v4l2_buf, V4L2_BUF_TYPE_VIDEO_CAPTURE);
+            if (ret != OK)
+              {
+                goto exit_this_app;
+              }
+
+#ifdef CONFIG_EXAMPLES_CAMERA_OUTPUT_LCD
+            nximage_draw((void *)v4l2_buf.m.userptr,
+                         VIDEO_HSIZE_QVGA, VIDEO_VSIZE_QVGA);
+#endif
+
+            ret = release_camimage(v_fd, &v4l2_buf);
+            if (ret != OK)
+              {
+                goto exit_this_app;
+              }
+
+            if (!is_eternal)
+              {
+                gettimeofday(&now, NULL);
+                timersub(&now, &start, &delta);
+                if (timercmp(&delta, &wait, >))

Review comment:
       -                if (timercmp(&delta, &wait, >))
   +                if (timercmp(&delta,
   +                             &wait,
   +                             >
   +                             ))
   




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org