![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
mbedとELECOM UCAM-DLA200HBKというwebカメラを使い、画像をjpgデータでSDカードまたは内部メモリに保存します。
Dependencies: SDHCFileSystem_ChanNFSSD mbed uvchost
main.cpp@1:dc4728f6882b, 2013-02-10 (annotated)
- Committer:
- Dromar
- Date:
- Sun Feb 10 15:43:38 2013 +0000
- Revision:
- 1:dc4728f6882b
- Parent:
- 0:3385ba2b8f13
mbed?ELECOM UCAM-DLA200HBK???web??????????jpg????SD??????????????????; ; mbed NXP LPC1768; StarBoard Orange; ELECOM UCAM-DLA200HBK; Amazon SDHC 4GB
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Dromar | 0:3385ba2b8f13 | 1 | #if 1 |
Dromar | 0:3385ba2b8f13 | 2 | #include "mbed.h" |
Dromar | 0:3385ba2b8f13 | 3 | #include "uvc.h" |
Dromar | 0:3385ba2b8f13 | 4 | //#include "msc.h" |
Dromar | 0:3385ba2b8f13 | 5 | #include "SDHCFileSystem.h" |
Dromar | 0:3385ba2b8f13 | 6 | #include<vector> |
Dromar | 0:3385ba2b8f13 | 7 | Serial pc(USBTX, USBRX);//Serial class |
Dromar | 0:3385ba2b8f13 | 8 | DigitalOut led1(LED1), led2(LED2), led3(LED3), led4(LED4); |
Dromar | 0:3385ba2b8f13 | 9 | |
Dromar | 0:3385ba2b8f13 | 10 | //SDFileSystem class |
Dromar | 0:3385ba2b8f13 | 11 | SDFileSystem sd(p5, p6, p7, p8, "sd"); |
Dromar | 0:3385ba2b8f13 | 12 | //#define FILENAME "/sd/cam%04d.jpg" |
Dromar | 0:3385ba2b8f13 | 13 | |
Dromar | 0:3385ba2b8f13 | 14 | //LocalFileSystem class |
Dromar | 0:3385ba2b8f13 | 15 | LocalFileSystem local("local"); |
Dromar | 0:3385ba2b8f13 | 16 | #define FILENAME "/local/cam%04d.jpg" |
Dromar | 0:3385ba2b8f13 | 17 | |
Dromar | 0:3385ba2b8f13 | 18 | #define INTERVAL_MS 10000 |
Dromar | 0:3385ba2b8f13 | 19 | #define CAM_N 1 |
Dromar | 0:3385ba2b8f13 | 20 | #define SHOT_N 1 |
Dromar | 0:3385ba2b8f13 | 21 | |
Dromar | 0:3385ba2b8f13 | 22 | vector <uvc*> vec_cam; |
Dromar | 0:3385ba2b8f13 | 23 | Timer t; |
Dromar | 0:3385ba2b8f13 | 24 | int main() |
Dromar | 0:3385ba2b8f13 | 25 | { |
Dromar | 0:3385ba2b8f13 | 26 | pc.baud(9600); |
Dromar | 0:3385ba2b8f13 | 27 | wait_ms(1000); |
Dromar | 0:3385ba2b8f13 | 28 | printf("%s\n", __FILE__); //sourcefilename printout |
Dromar | 0:3385ba2b8f13 | 29 | printf("start!!\n"); |
Dromar | 0:3385ba2b8f13 | 30 | //msc* usb = new msc("usb"); //usb storage class |
Dromar | 0:3385ba2b8f13 | 31 | //if (usb->setup() < 0) exit(1); |
Dromar | 0:3385ba2b8f13 | 32 | |
Dromar | 0:3385ba2b8f13 | 33 | FILE *fp; |
Dromar | 0:3385ba2b8f13 | 34 | if ((fp=fopen(FILENAME,"wb")) == NULL) return -1; //"wb" : write and binary mode |
Dromar | 0:3385ba2b8f13 | 35 | |
Dromar | 0:3385ba2b8f13 | 36 | for(int n = 0; n < CAM_N; n++) { |
Dromar | 0:3385ba2b8f13 | 37 | uvc* cam = new uvc(n); |
Dromar | 0:3385ba2b8f13 | 38 | cam->SetImageSize(320, 240); |
Dromar | 0:3385ba2b8f13 | 39 | cam->SetFrameInterval(2000000); |
Dromar | 0:3385ba2b8f13 | 40 | if (cam->setup() < 0) { |
Dromar | 0:3385ba2b8f13 | 41 | break; |
Dromar | 0:3385ba2b8f13 | 42 | } |
Dromar | 0:3385ba2b8f13 | 43 | vec_cam.push_back(cam); |
Dromar | 0:3385ba2b8f13 | 44 | } |
Dromar | 0:3385ba2b8f13 | 45 | t.start(); |
Dromar | 0:3385ba2b8f13 | 46 | for (int n = 0; n < SHOT_N; n++) { |
Dromar | 0:3385ba2b8f13 | 47 | int cam = n % vec_cam.size(); |
Dromar | 0:3385ba2b8f13 | 48 | t.reset(); |
Dromar | 0:3385ba2b8f13 | 49 | char path[32]; |
Dromar | 0:3385ba2b8f13 | 50 | //snprintf(path, sizeof(path), "/usb/cam%1d%03d.jpg", cam, n%100); |
Dromar | 0:3385ba2b8f13 | 51 | snprintf(path, sizeof(path), FILENAME, n); |
Dromar | 0:3385ba2b8f13 | 52 | int len = vec_cam[cam]->get_jpeg(path); |
Dromar | 0:3385ba2b8f13 | 53 | printf("%d %s %d\n", n, path, len); |
Dromar | 0:3385ba2b8f13 | 54 | while(t.read_ms() < INTERVAL_MS) { |
Dromar | 0:3385ba2b8f13 | 55 | for(int n = 0; n < vec_cam.size(); n++) { |
Dromar | 0:3385ba2b8f13 | 56 | vec_cam[n]->poll(); |
Dromar | 0:3385ba2b8f13 | 57 | } |
Dromar | 0:3385ba2b8f13 | 58 | } |
Dromar | 0:3385ba2b8f13 | 59 | } |
Dromar | 0:3385ba2b8f13 | 60 | printf("finish!!\n"); |
Dromar | 0:3385ba2b8f13 | 61 | fclose(fp); |
Dromar | 0:3385ba2b8f13 | 62 | exit(1); |
Dromar | 0:3385ba2b8f13 | 63 | } |
Dromar | 0:3385ba2b8f13 | 64 | #endif |