Camera in sample for GR-PEACH. This sample works on GR-LYCHEE besides GR-PEACH.

Video Links on how to setup and run Camera_in Application:

Your video will be live at: https://youtu.be/XNH8jLhjeS4 Part1 of 1

Camera in sample for GR-PEACH or GR-LYCHEE. While USER_BUTTON0 is pressed, it will save the camera image(default is jpeg fotmat) to USB memory or SD card.
If both USB and SD are inserted, GR-PEACH or GR-LYCHEE connect to the previously detected device.

The default setting of serial communication (baud rate etc.) in mbed is shown the following link.
Please refer to the link and change the settings of your PC terminal software.
The default value of baud rate in mbed is 9600, and this application uses baud rate 9600.
https://developer.mbed.org/teams/Renesas/wiki/GR-PEACH-Getting-Started#install-the-usb-serial-communication

Please refer to following link about Audio/Camera Shield.
https://developer.mbed.org/teams/Renesas/wiki/Audio_Camera-shield

You can configure this sample application via the following definitions. If you set to 1, it will save the video file as a AVI format:

main.cpp

/**** User Selection *********/
#define SAVE_FILE_TYPE         (0)     /* Select  0(Image(.jpg)) or 1(Movie(.avi)) */
/*****************************/


  • USB channel available in this sample program
    By default, the GR-PEACH's USB connector (USB0) is configured to be used. When using USB0, please close GR-PEACH's JP3.
    /media/uploads/RyoheiHagimoto/usb.jpg


    Or, you can use the Audio/Camera Shield's USB connector (USB1). When using USB1, you need to close JP1 of Audio/Camera Shield.
    /media/uploads/dkato/audiocamerashield_jp1.jpg


  • Specify each configuration
    To specify camera and LCD, add camera-type and lcd-type to mbed_app.json.
    For details, please refer to mbed-gr-libs / README.md.

mbed_app.json

{
    "config": {
        "camera":{
            "help": "0:disable 1:enable",
            "value": "1"
        },
        "camera-type":{
            "help": "Please see mbed-gr-libs/README.md",
            "value": "CAMERA_CVBS"
        },
        "lcd":{
            "help": "0:disable 1:enable",
            "value": "0"
        },
        "lcd-type":{
            "help": "Please see mbed-gr-libs/README.md",
            "value": "GR_PEACH_4_3INCH_SHIELD"
        },
        "usb-host-ch":{
            "help": "(for GR-PEACH) 0:ch0 1:ch1",
            "value": "1"
        },
        "audio-camera-shield":{
            "help": "(for GR-PEACH) 0:not use 1:use",
            "value": "1"
        }
    }
}

bitmap.h

Committer:
Osamu Nakamura
Date:
2017-03-21
Revision:
2:9d98159fa9c9
Parent:
0:2f1caf4ce924

File content as of revision 2:9d98159fa9c9:

/** @file bitmap.h */
#include "mbed.h"

/** A class to communicate a bitmap
 *
 */
class bitmap {
public:

    /** convert RGB888 to bitmap
     *
     * @param file_name save file name
     * @param buf data buffer address
     * @param pic_width picture width
     * @param pic_height picture height
     * @return save data size
     */
    int Rgb888ToBmp(char * file_name, uint8_t * buf, unsigned long pic_width, unsigned long pic_height) {
        unsigned long offset_size = 54;
        unsigned long buf_stride = (((pic_width * 4u) + 31u) & ~31u);
        unsigned long pic_size = buf_stride * pic_height;
        unsigned long file_size = 0;
        int save_file_size = 0;
        int write_index = (buf_stride * pic_height) - buf_stride;
        unsigned long cnt;
        uint8_t wk_bitmap_buf[16];
        FILE * fp = fopen(file_name, "w");

        if (fp != NULL) {
            file_size = pic_size + offset_size;

            /* BITMAPFILEHEADER */
            wk_bitmap_buf[0]  = 'B';
            wk_bitmap_buf[1]  = 'M';
            wk_bitmap_buf[2]  = (unsigned char)(file_size >> 0);   /* bfSize */
            wk_bitmap_buf[3]  = (unsigned char)(file_size >> 8);   /* bfSize */
            wk_bitmap_buf[4]  = (unsigned char)(file_size >> 16);  /* bfSize */
            wk_bitmap_buf[5]  = (unsigned char)(file_size >> 24);  /* bfSize */
            wk_bitmap_buf[6]  = 0;  /* bfReserved1 */
            wk_bitmap_buf[7]  = 0;  /* bfReserved1 */
            wk_bitmap_buf[8]  = 0;  /* bfReserved2 */
            wk_bitmap_buf[9]  = 0;  /* bfReserved2 */
            wk_bitmap_buf[10] = (unsigned char)(offset_size >> 0);   /* bfOffBits */
            wk_bitmap_buf[11] = (unsigned char)(offset_size >> 8);   /* bfOffBits */
            wk_bitmap_buf[12] = (unsigned char)(offset_size >> 16);  /* bfOffBits */
            wk_bitmap_buf[13] = (unsigned char)(offset_size >> 24);  /* bfOffBits */
            fwrite(wk_bitmap_buf, sizeof(char), 14, fp);

            /* BITMAPINFOHEADER */
            wk_bitmap_buf[0]  = 40; /* biSize */
            wk_bitmap_buf[1]  = 0;  /* biSize */
            wk_bitmap_buf[2]  = 0;  /* biSize */
            wk_bitmap_buf[3]  = 0;  /* biSize */
            wk_bitmap_buf[4]  = (unsigned char)(pic_width >> 0);    /* biWidth */
            wk_bitmap_buf[5]  = (unsigned char)(pic_width >> 8);    /* biWidth */
            wk_bitmap_buf[6]  = (unsigned char)(pic_width >> 16);   /* biWidth */
            wk_bitmap_buf[7]  = (unsigned char)(pic_width >> 24);   /* biWidth */
            wk_bitmap_buf[8]  = (unsigned char)(pic_height >> 0);   /* biHeight */
            wk_bitmap_buf[9]  = (unsigned char)(pic_height >> 8);   /* biHeight */
            wk_bitmap_buf[10] = (unsigned char)(pic_height >> 16);  /* biHeight */
            wk_bitmap_buf[11] = (unsigned char)(pic_height >> 24);  /* biHeight */
            wk_bitmap_buf[12] = 1;  /* biPlanes */
            wk_bitmap_buf[13] = 0;  /* biPlanes */
            wk_bitmap_buf[14] = 32; /* biBitCount */
            wk_bitmap_buf[15] = 0;  /* biBitCount */
            fwrite(wk_bitmap_buf, sizeof(char), 16, fp);

            wk_bitmap_buf[0]  = 0;  /* biCopmression */
            wk_bitmap_buf[1]  = 0;  /* biCopmression */
            wk_bitmap_buf[2]  = 0;  /* biCopmression */
            wk_bitmap_buf[3]  = 0;  /* biCopmression */
            wk_bitmap_buf[4]  = (unsigned char)(pic_size >> 0);   /* biSizeImage */
            wk_bitmap_buf[5]  = (unsigned char)(pic_size >> 8);   /* biSizeImage */
            wk_bitmap_buf[6]  = (unsigned char)(pic_size >> 16);  /* biSizeImage */
            wk_bitmap_buf[7]  = (unsigned char)(pic_size >> 24);  /* biSizeImage */
            wk_bitmap_buf[8]  = 0;  /* biXPixPerMeter */
            wk_bitmap_buf[9]  = 0;  /* biXPixPerMeter */
            wk_bitmap_buf[10] = 0;  /* biXPixPerMeter */
            wk_bitmap_buf[11] = 0;  /* biXPixPerMeter */
            wk_bitmap_buf[12] = 0;  /* biYPixPerMeter */
            wk_bitmap_buf[13] = 0;  /* biYPixPerMeter */
            wk_bitmap_buf[14] = 0;  /* biYPixPerMeter */
            wk_bitmap_buf[15] = 0;  /* biYPixPerMeter */
            fwrite(wk_bitmap_buf, sizeof(char), 16, fp);

            wk_bitmap_buf[0]  = 0;  /* biClrUsed */
            wk_bitmap_buf[1]  = 0;  /* biClrUsed */
            wk_bitmap_buf[2]  = 0;  /* biClrUsed */
            wk_bitmap_buf[3]  = 0;  /* biClrUsed */
            wk_bitmap_buf[4]  = 0;  /* biCirImportant */
            wk_bitmap_buf[5]  = 0;  /* biCirImportant */
            wk_bitmap_buf[6]  = 0;  /* biCirImportant */
            wk_bitmap_buf[7]  = 0;  /* biCirImportant */
            fwrite(wk_bitmap_buf, sizeof(char), 8, fp);

            save_file_size    = 54;
            for (cnt = 0; cnt < pic_height; cnt ++) {
                save_file_size += fwrite(&buf[write_index], sizeof(char), buf_stride, fp);
                write_index -= buf_stride;
            }
            fclose(fp);
        }

        return (int)save_file_size;
    };
};