This is a test program for Camera Module(C328, LJ-DSC02)
Dependencies: CameraC328 SDFileSystem mbed-src
Fork of Camera_TestProgram_2015 by
Prerequisite
This example stores the image data acquired from the camera on a micro sd card.
To implement this function, you need a Platform board, camera module.
Available camera modules are C328, LJ-DSC02. Because the cameras listed above all have similar internal protocols.
This example uses LJ-DSC02.
- WIZwiki-W7500 from WIZnet (Platform board)
- LJ-DSC02 (Camera module)
- Micro SD Card
Hardware Configuration
- connect Camera module
Software
Init resolution and frame of image
#define USE_JPEG_HIGH_RESOLUTION 1 static const int CAPTURE_FRAMES = 1;
Revision 2:09815843204c, committed 2015-07-21
- Comitter:
- Ricky_Kwon
- Date:
- Tue Jul 21 16:22:03 2015 +0000
- Parent:
- 1:7e547bf0f166
- Child:
- 3:92e4afa57824
- Commit message:
- Except JPEG capture and erase the unnecessary.
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Tue Jul 21 05:06:05 2015 +0000 +++ b/main.cpp Tue Jul 21 16:22:03 2015 +0000 @@ -22,10 +22,7 @@ /* * Variables. */ -static const int CAPTURE_FRAMES = 5; -static const int RAWIMG_X = 10; -static const int RAWIMG_Y = 10; -static char buf[RAWIMG_X * RAWIMG_Y * 2]; +static const int CAPTURE_FRAMES = 1; static FILE *fp_jpeg; /* @@ -36,19 +33,7 @@ #else LocalFileSystem fs("fs"); #endif -CameraC328 camera(PA_14, PA_13, CameraC328::Baud14400); -/** - * A callback function for uncompressed images. - * Please do NOT block this callback function. - * Because the camera module transmit image datas continuously. - * - * @param done a done number of packets. - * @param total a total number of packets. - * @param c received data. - */ -void uncompressed_callback(size_t done, size_t total, char c) { - buf[done - 1] = c; -} +CameraC328 camera(PA_14, PA_13, CameraC328::Baud115200); /** * A callback function for jpeg images. @@ -78,88 +63,6 @@ } /** - * A test function for uncompressed snapshot picture. - */ -void test_uncompressed_snapshot_picture(void) { - CameraC328::ErrorNumber err = CameraC328::NoError; - - err = camera.init(CameraC328::Color16bit, CameraC328::RawResolution80x60, CameraC328::JpegResolution160x128); - if (CameraC328::NoError == err) { - printf("[ OK ] : CameraC328::init\n"); - } else { - printf("[FAIL] : CameraC328::init (Error=%02X)\n", (int)err); - } - - for (int i = 0; i < CAPTURE_FRAMES; i++) { - err = camera.getUncompressedSnapshotPicture(uncompressed_callback); - if (CameraC328::NoError == err) { - printf("[ OK ] : CameraC328::getUncompressedSnapshotPicture\n"); - } else { - printf("[FAIL] : CameraC328::getUncompressedSnapshotPicture (Error=%02X)\n", (int)err); - } - - char fname[64]; - snprintf(fname, sizeof(fname), "/fs/ucss%04d.ppm", i); - FILE *fp = fopen(fname, "w"); - fprintf(fp, "P3\n"); - fprintf(fp, "%d %d\n", RAWIMG_X, RAWIMG_Y); - fprintf(fp, "%d\n", 255); - for (int y = 0; y < RAWIMG_Y; y++) { - for (int x = 0; x < RAWIMG_X; x++) { - int adrofs = y * (RAWIMG_X * 2) + (x * 2); - uint16_t dat = (buf[adrofs + 0] << 8) | (buf[adrofs + 1] << 0); - uint8_t r = ((dat >> 11) & 0x1f) << 3; - uint8_t g = ((dat >> 5) & 0x3f) << 2; - uint8_t b = ((dat >> 0) & 0x1f) << 3; - fprintf(fp,"%d %d %d\n", r, g, b); - } - } - fclose(fp); - } -} - -/** - * A test function for uncompressed preview picture. - */ -void test_uncompressed_preview_picture(void) { - CameraC328::ErrorNumber err = CameraC328::NoError; - - err = camera.init(CameraC328::Color16bit, CameraC328::RawResolution80x60, CameraC328::JpegResolution160x128); - if (CameraC328::NoError == err) { - printf("[ OK ] : CameraC328::init\n"); - } else { - printf("[FAIL] : CameraC328::init (Error=%02X)\n", (int)err); - } - - for (int i = 0; i < CAPTURE_FRAMES; i++) { - err = camera.getUncompressedPreviewPicture(uncompressed_callback); - if (CameraC328::NoError == err) { - printf("[ OK ] : CameraC328::getUncompressedPreviewPicture\n"); - } else { - printf("[FAIL] : CameraC328::getUncompressedPreviewPicture (Error=%02X)\n", (int)err); - } - - char fname[64]; - snprintf(fname, sizeof(fname), "/fs/ucpv%04d.ppm", i); - FILE *fp = fopen(fname, "w"); - fprintf(fp, "P3\n"); - fprintf(fp, "%d %d\n", RAWIMG_X, RAWIMG_Y); - fprintf(fp, "%d\n", 255); - for (int y = 0; y < RAWIMG_Y; y++) { - for (int x = 0; x < RAWIMG_X; x++) { - int adrofs = y * (RAWIMG_X * 2) + (x * 2); - uint16_t dat = (buf[adrofs + 0] << 8) | (buf[adrofs + 1] << 0); - uint8_t r = ((dat >> 11) & 0x1f) << 3; - uint8_t g = ((dat >> 5) & 0x3f) << 2; - uint8_t b = ((dat >> 0) & 0x1f) << 3; - fprintf(fp,"%d %d %d\n", r, g, b); - } - } - fclose(fp); - } -} - -/** * A test function for jpeg snapshot picture. */ void test_jpeg_snapshot_picture(void) { @@ -193,39 +96,6 @@ } /** - * A test function for jpeg preview picture. - */ -void test_jpeg_preview_picture(void) { - CameraC328::ErrorNumber err = CameraC328::NoError; - -#if USE_JPEG_HIGH_RESOLUTION - err = camera.init(CameraC328::Jpeg, CameraC328::RawResolution80x60, CameraC328::JpegResolution640x480); -#else - err = camera.init(CameraC328::Jpeg, CameraC328::RawResolution80x60, CameraC328::JpegResolution320x240); -#endif - if (CameraC328::NoError == err) { - printf("[ OK ] : CameraC328::init\n"); - } else { - printf("[FAIL] : CameraC328::init (Error=%02X)\n", (int)err); - } - - for (int i = 0; i < CAPTURE_FRAMES; i++) { - char fname[64]; - snprintf(fname, sizeof(fname), "/fs/jppv%04d.jpg", i); - fp_jpeg = fopen(fname, "w"); - - err = camera.getJpegPreviewPicture(jpeg_callback); - if (CameraC328::NoError == err) { - printf("[ OK ] : CameraC328::getJpegPreviewPicture\n"); - } else { - printf("[FAIL] : CameraC328::getJpegPreviewPicture (Error=%02X)\n", (int)err); - } - - fclose(fp_jpeg); - } -} - -/** * A entry point. */ int main() { @@ -235,22 +105,6 @@ printf("==========\n"); sync(); -// test_uncompressed_snapshot_picture(); -// test_uncompressed_preview_picture(); -// test_jpeg_preview_picture(); + test_jpeg_snapshot_picture(); - - /*printf("Hello World!\n"); - - mkdir("/fs/mydir", 0777); - - FILE *fp = fopen("/fs/mydir/sdtest.txt", "w"); - if(fp == NULL) { - error("Could not open file for write\n"); - } - fprintf(fp, "Hello fun SD Card World!"); - fclose(fp); - - printf("Goodbye World!\n"); - return 0;*/ }