Sample code of section 3 in Nov 2014 issue of the Interface Magazine, published by CQ publishing in Japan. CQ出版社インターフェース誌 2014年11月号3章に掲載のサンプルコードです. FRDM-K64FにOV7670カメラを接続して映像を取得するとともに,簡単なフィルタ処理も施すサンプルです.このコードのうちカメラ制御部には,Sadaei Osakabe氏のコードを流用させていただいています.
Dependencies: SDFileSystem TextLCD mbed
このコードでは,Arduino用のLCDシールド(http://www.switch-science.com/catalog/724/)を接続することを想定しています.ただしLCDは必須ではないので,LCDを使わない場合は表示用のコードはコメントアウトしてください.
main.cpp@0:f31ceb6058cb, 2014-09-24 (annotated)
- Committer:
- smorioka
- Date:
- Wed Sep 24 20:44:56 2014 +0000
- Revision:
- 0:f31ceb6058cb
First release
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
smorioka | 0:f31ceb6058cb | 1 | /* |
smorioka | 0:f31ceb6058cb | 2 | * Copyright (c) 2014, Sumio Morioka |
smorioka | 0:f31ceb6058cb | 3 | * All rights reserved. |
smorioka | 0:f31ceb6058cb | 4 | * |
smorioka | 0:f31ceb6058cb | 5 | * This source code was originally written by Dr.Sumio Morioka for use in the Nov 2014 issue of |
smorioka | 0:f31ceb6058cb | 6 | * "the Interface magazine", published by CQ publishing Co.Ltd in Japan (http://www.cqpub.co.jp). |
smorioka | 0:f31ceb6058cb | 7 | * The author has no responsibility on any results caused by using this code. |
smorioka | 0:f31ceb6058cb | 8 | * |
smorioka | 0:f31ceb6058cb | 9 | * - Distribution date of this code: Sep 24, 2014 |
smorioka | 0:f31ceb6058cb | 10 | * - Author: Dr.Sumio Morioka (http://www002.upp.so-net.ne.jp/morioka) |
smorioka | 0:f31ceb6058cb | 11 | * |
smorioka | 0:f31ceb6058cb | 12 | * |
smorioka | 0:f31ceb6058cb | 13 | * IMPORTANT NOTICE: |
smorioka | 0:f31ceb6058cb | 14 | * Redistribution and use in source and binary forms, with or without |
smorioka | 0:f31ceb6058cb | 15 | * modification, are permitted provided that the following conditions are met: |
smorioka | 0:f31ceb6058cb | 16 | * * Redistributions of source code must retain the above copyright |
smorioka | 0:f31ceb6058cb | 17 | * notice, this list of conditions and the following disclaimer. |
smorioka | 0:f31ceb6058cb | 18 | * * Redistributions in binary form must reproduce the above copyright |
smorioka | 0:f31ceb6058cb | 19 | * notice, this list of conditions and the following disclaimer in the |
smorioka | 0:f31ceb6058cb | 20 | * documentation and/or other materials provided with the distribution. |
smorioka | 0:f31ceb6058cb | 21 | * * Neither the name of the copyright holder nor the |
smorioka | 0:f31ceb6058cb | 22 | * names of its contributors may be used to endorse or promote products |
smorioka | 0:f31ceb6058cb | 23 | * derived from this software without specific prior written permission. |
smorioka | 0:f31ceb6058cb | 24 | * |
smorioka | 0:f31ceb6058cb | 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
smorioka | 0:f31ceb6058cb | 26 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
smorioka | 0:f31ceb6058cb | 27 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
smorioka | 0:f31ceb6058cb | 28 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY |
smorioka | 0:f31ceb6058cb | 29 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
smorioka | 0:f31ceb6058cb | 30 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
smorioka | 0:f31ceb6058cb | 31 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
smorioka | 0:f31ceb6058cb | 32 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
smorioka | 0:f31ceb6058cb | 33 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
smorioka | 0:f31ceb6058cb | 34 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
smorioka | 0:f31ceb6058cb | 35 | */ |
smorioka | 0:f31ceb6058cb | 36 | |
smorioka | 0:f31ceb6058cb | 37 | #include "mbed.h" |
smorioka | 0:f31ceb6058cb | 38 | #include "SDFileSystem.h" |
smorioka | 0:f31ceb6058cb | 39 | #include "TextLCD.h" |
smorioka | 0:f31ceb6058cb | 40 | #include "ov7670.h" |
smorioka | 0:f31ceb6058cb | 41 | |
smorioka | 0:f31ceb6058cb | 42 | DigitalOut led1(LED1), led2(LED2), led3(LED3); |
smorioka | 0:f31ceb6058cb | 43 | SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd"); // MOSI, MISO, SCK, CS |
smorioka | 0:f31ceb6058cb | 44 | TextLCD lcd(PTD3, PTD2, PTA2, PTB23, PTA1, PTB9); // Arduino LCD sheild; |
smorioka | 0:f31ceb6058cb | 45 | |
smorioka | 0:f31ceb6058cb | 46 | OV7670 camera( |
smorioka | 0:f31ceb6058cb | 47 | PTE25,PTE24, // SDA,SCL(I2C / SCCB) |
smorioka | 0:f31ceb6058cb | 48 | PTB2,PTB3,PTB10, // VSYNC,HREF,WEN(FIFO) |
smorioka | 0:f31ceb6058cb | 49 | PTC5,PTC7,PTC0,PTC9,PTC8,PTC1,PTB19,PTB18, // D7-D0 |
smorioka | 0:f31ceb6058cb | 50 | PTB11,PTC11,PTC10); // RRST,OE,RCLK |
smorioka | 0:f31ceb6058cb | 51 | |
smorioka | 0:f31ceb6058cb | 52 | Timer tmr; |
smorioka | 0:f31ceb6058cb | 53 | |
smorioka | 0:f31ceb6058cb | 54 | //#define QQVGA |
smorioka | 0:f31ceb6058cb | 55 | #define QVGA |
smorioka | 0:f31ceb6058cb | 56 | //#define VGA34 |
smorioka | 0:f31ceb6058cb | 57 | |
smorioka | 0:f31ceb6058cb | 58 | #ifdef QQVGA |
smorioka | 0:f31ceb6058cb | 59 | #define SIZEX 160 |
smorioka | 0:f31ceb6058cb | 60 | #define SIZEY 120 |
smorioka | 0:f31ceb6058cb | 61 | #endif |
smorioka | 0:f31ceb6058cb | 62 | |
smorioka | 0:f31ceb6058cb | 63 | #ifdef QVGA |
smorioka | 0:f31ceb6058cb | 64 | #define SIZEX 320 |
smorioka | 0:f31ceb6058cb | 65 | #define SIZEY 240 |
smorioka | 0:f31ceb6058cb | 66 | #endif |
smorioka | 0:f31ceb6058cb | 67 | |
smorioka | 0:f31ceb6058cb | 68 | #ifdef VGA34 |
smorioka | 0:f31ceb6058cb | 69 | #define SIZEX 480 |
smorioka | 0:f31ceb6058cb | 70 | #define SIZEY 360 |
smorioka | 0:f31ceb6058cb | 71 | #endif |
smorioka | 0:f31ceb6058cb | 72 | |
smorioka | 0:f31ceb6058cb | 73 | unsigned char image_buf_g[SIZEX * SIZEY * 3]; |
smorioka | 0:f31ceb6058cb | 74 | |
smorioka | 0:f31ceb6058cb | 75 | void cam_cap(void); |
smorioka | 0:f31ceb6058cb | 76 | void save_bmp(void); |
smorioka | 0:f31ceb6058cb | 77 | |
smorioka | 0:f31ceb6058cb | 78 | int memfree(void) |
smorioka | 0:f31ceb6058cb | 79 | { |
smorioka | 0:f31ceb6058cb | 80 | int ret = 1; |
smorioka | 0:f31ceb6058cb | 81 | while (1) { |
smorioka | 0:f31ceb6058cb | 82 | char *p = (char *)malloc(ret); |
smorioka | 0:f31ceb6058cb | 83 | if (p == NULL) |
smorioka | 0:f31ceb6058cb | 84 | break; |
smorioka | 0:f31ceb6058cb | 85 | free(p); |
smorioka | 0:f31ceb6058cb | 86 | ret++; |
smorioka | 0:f31ceb6058cb | 87 | } |
smorioka | 0:f31ceb6058cb | 88 | return (ret - 1); |
smorioka | 0:f31ceb6058cb | 89 | } |
smorioka | 0:f31ceb6058cb | 90 | |
smorioka | 0:f31ceb6058cb | 91 | int main() |
smorioka | 0:f31ceb6058cb | 92 | { |
smorioka | 0:f31ceb6058cb | 93 | led1 = 0; |
smorioka | 0:f31ceb6058cb | 94 | led2 = 0; |
smorioka | 0:f31ceb6058cb | 95 | led3 = 0; |
smorioka | 0:f31ceb6058cb | 96 | |
smorioka | 0:f31ceb6058cb | 97 | ///////////////////////////////////////// |
smorioka | 0:f31ceb6058cb | 98 | // init camera |
smorioka | 0:f31ceb6058cb | 99 | camera.WriteReg(0x12, 0x80); // com7; reset |
smorioka | 0:f31ceb6058cb | 100 | wait_ms(200); |
smorioka | 0:f31ceb6058cb | 101 | |
smorioka | 0:f31ceb6058cb | 102 | camera.InitDefaultReg(); |
smorioka | 0:f31ceb6058cb | 103 | |
smorioka | 0:f31ceb6058cb | 104 | // negate vsync |
smorioka | 0:f31ceb6058cb | 105 | camera.WriteReg(0x15, 0x02); // com10; negative vsync |
smorioka | 0:f31ceb6058cb | 106 | |
smorioka | 0:f31ceb6058cb | 107 | #ifdef QQVGA |
smorioka | 0:f31ceb6058cb | 108 | camera.InitQQVGA(); |
smorioka | 0:f31ceb6058cb | 109 | #endif |
smorioka | 0:f31ceb6058cb | 110 | #ifdef QVGA |
smorioka | 0:f31ceb6058cb | 111 | camera.InitQVGA(); |
smorioka | 0:f31ceb6058cb | 112 | #endif |
smorioka | 0:f31ceb6058cb | 113 | #ifdef VGA34 |
smorioka | 0:f31ceb6058cb | 114 | camera.InitVGA_3_4(); |
smorioka | 0:f31ceb6058cb | 115 | #endif |
smorioka | 0:f31ceb6058cb | 116 | |
smorioka | 0:f31ceb6058cb | 117 | // data format |
smorioka | 0:f31ceb6058cb | 118 | camera.WriteReg(0x12, 0x04 + 0); // com7 RGB (bit1...test pattern) |
smorioka | 0:f31ceb6058cb | 119 | camera.WriteReg(0x40, 0xD0); // com15 RGB565 |
smorioka | 0:f31ceb6058cb | 120 | camera.WriteReg(0x8c, 0x00); // RGB444 |
smorioka | 0:f31ceb6058cb | 121 | |
smorioka | 0:f31ceb6058cb | 122 | wait_ms(300); |
smorioka | 0:f31ceb6058cb | 123 | |
smorioka | 0:f31ceb6058cb | 124 | /////////////////////////////////////// |
smorioka | 0:f31ceb6058cb | 125 | // display free memory size |
smorioka | 0:f31ceb6058cb | 126 | int cur_mem = memfree(); |
smorioka | 0:f31ceb6058cb | 127 | lcd.locate(0, 0); |
smorioka | 0:f31ceb6058cb | 128 | lcd.printf("mem %d", cur_mem); |
smorioka | 0:f31ceb6058cb | 129 | |
smorioka | 0:f31ceb6058cb | 130 | /////////////////////////////////////// |
smorioka | 0:f31ceb6058cb | 131 | // capture |
smorioka | 0:f31ceb6058cb | 132 | tmr.reset(); |
smorioka | 0:f31ceb6058cb | 133 | tmr.start(); // timer |
smorioka | 0:f31ceb6058cb | 134 | |
smorioka | 0:f31ceb6058cb | 135 | cam_cap(); // capture photo |
smorioka | 0:f31ceb6058cb | 136 | |
smorioka | 0:f31ceb6058cb | 137 | tmr.stop(); // timer |
smorioka | 0:f31ceb6058cb | 138 | lcd.locate(0, 0); |
smorioka | 0:f31ceb6058cb | 139 | lcd.printf("cap %dms", tmr.read_ms()); |
smorioka | 0:f31ceb6058cb | 140 | |
smorioka | 0:f31ceb6058cb | 141 | //////////////////////////////////////// |
smorioka | 0:f31ceb6058cb | 142 | // apply filter |
smorioka | 0:f31ceb6058cb | 143 | tmr.reset(); |
smorioka | 0:f31ceb6058cb | 144 | tmr.start(); // timer |
smorioka | 0:f31ceb6058cb | 145 | { |
smorioka | 0:f31ceb6058cb | 146 | int kernel_size = 3; |
smorioka | 0:f31ceb6058cb | 147 | int kernel_dotnum = kernel_size * kernel_size; |
smorioka | 0:f31ceb6058cb | 148 | int kernel_halfsize = (kernel_size - 1) / 2; |
smorioka | 0:f31ceb6058cb | 149 | |
smorioka | 0:f31ceb6058cb | 150 | // calc average value |
smorioka | 0:f31ceb6058cb | 151 | for (int y = 0; y < SIZEY; y++) { |
smorioka | 0:f31ceb6058cb | 152 | int r_new, g_new, b_new; |
smorioka | 0:f31ceb6058cb | 153 | |
smorioka | 0:f31ceb6058cb | 154 | // scan |
smorioka | 0:f31ceb6058cb | 155 | for (int x = 0; x < SIZEX; x++) { |
smorioka | 0:f31ceb6058cb | 156 | int r, g, b; |
smorioka | 0:f31ceb6058cb | 157 | |
smorioka | 0:f31ceb6058cb | 158 | int acc_r = 0; |
smorioka | 0:f31ceb6058cb | 159 | int acc_g = 0; |
smorioka | 0:f31ceb6058cb | 160 | int acc_b = 0; |
smorioka | 0:f31ceb6058cb | 161 | |
smorioka | 0:f31ceb6058cb | 162 | for (int ky = 0; ky < kernel_size; ky++) { |
smorioka | 0:f31ceb6058cb | 163 | int ypos = y - kernel_halfsize + ky; |
smorioka | 0:f31ceb6058cb | 164 | |
smorioka | 0:f31ceb6058cb | 165 | if (ypos < 0 || ypos >= SIZEY) |
smorioka | 0:f31ceb6058cb | 166 | continue; |
smorioka | 0:f31ceb6058cb | 167 | |
smorioka | 0:f31ceb6058cb | 168 | for (int kx = 0; kx < kernel_size; kx++) { |
smorioka | 0:f31ceb6058cb | 169 | int xpos = x - kernel_halfsize + kx; |
smorioka | 0:f31ceb6058cb | 170 | |
smorioka | 0:f31ceb6058cb | 171 | if (xpos < 0 || xpos >= SIZEX) |
smorioka | 0:f31ceb6058cb | 172 | continue; |
smorioka | 0:f31ceb6058cb | 173 | |
smorioka | 0:f31ceb6058cb | 174 | b = image_buf_g[(ypos * SIZEX + xpos) * 3]; |
smorioka | 0:f31ceb6058cb | 175 | g = image_buf_g[(ypos * SIZEX + xpos) * 3 + 1]; |
smorioka | 0:f31ceb6058cb | 176 | r = image_buf_g[(ypos * SIZEX + xpos) * 3 + 2]; |
smorioka | 0:f31ceb6058cb | 177 | |
smorioka | 0:f31ceb6058cb | 178 | acc_r += r; |
smorioka | 0:f31ceb6058cb | 179 | acc_g += g; |
smorioka | 0:f31ceb6058cb | 180 | acc_b += b; |
smorioka | 0:f31ceb6058cb | 181 | } |
smorioka | 0:f31ceb6058cb | 182 | } |
smorioka | 0:f31ceb6058cb | 183 | |
smorioka | 0:f31ceb6058cb | 184 | r_new = (unsigned char)(acc_r / kernel_dotnum); |
smorioka | 0:f31ceb6058cb | 185 | g_new = (unsigned char)(acc_g / kernel_dotnum); |
smorioka | 0:f31ceb6058cb | 186 | b_new = (unsigned char)(acc_b / kernel_dotnum); |
smorioka | 0:f31ceb6058cb | 187 | |
smorioka | 0:f31ceb6058cb | 188 | image_buf_g[(y * SIZEX + x) * 3] = b_new; |
smorioka | 0:f31ceb6058cb | 189 | image_buf_g[(y * SIZEX + x) * 3 + 1] = g_new; |
smorioka | 0:f31ceb6058cb | 190 | image_buf_g[(y * SIZEX + x) * 3 + 2] = r_new; |
smorioka | 0:f31ceb6058cb | 191 | } |
smorioka | 0:f31ceb6058cb | 192 | } |
smorioka | 0:f31ceb6058cb | 193 | } |
smorioka | 0:f31ceb6058cb | 194 | tmr.stop(); // timer |
smorioka | 0:f31ceb6058cb | 195 | lcd.locate(0, 1); |
smorioka | 0:f31ceb6058cb | 196 | lcd.printf("flt %dms", tmr.read_ms()); |
smorioka | 0:f31ceb6058cb | 197 | |
smorioka | 0:f31ceb6058cb | 198 | //////////////////////////////////////// |
smorioka | 0:f31ceb6058cb | 199 | // save BMP |
smorioka | 0:f31ceb6058cb | 200 | tmr.reset(); |
smorioka | 0:f31ceb6058cb | 201 | tmr.start(); // timer |
smorioka | 0:f31ceb6058cb | 202 | |
smorioka | 0:f31ceb6058cb | 203 | save_bmp(); |
smorioka | 0:f31ceb6058cb | 204 | |
smorioka | 0:f31ceb6058cb | 205 | tmr.stop(); // timer |
smorioka | 0:f31ceb6058cb | 206 | // lcd.locate(0, 1); |
smorioka | 0:f31ceb6058cb | 207 | // lcd.printf("bmp %dms", tmr.read_ms()); |
smorioka | 0:f31ceb6058cb | 208 | |
smorioka | 0:f31ceb6058cb | 209 | ////////////////////////////////////////////////// |
smorioka | 0:f31ceb6058cb | 210 | // (stop) |
smorioka | 0:f31ceb6058cb | 211 | while (1) { |
smorioka | 0:f31ceb6058cb | 212 | led1 = 1; |
smorioka | 0:f31ceb6058cb | 213 | wait_ms(100); |
smorioka | 0:f31ceb6058cb | 214 | } |
smorioka | 0:f31ceb6058cb | 215 | } |
smorioka | 0:f31ceb6058cb | 216 | |
smorioka | 0:f31ceb6058cb | 217 | |
smorioka | 0:f31ceb6058cb | 218 | void save_bmp(void) |
smorioka | 0:f31ceb6058cb | 219 | { |
smorioka | 0:f31ceb6058cb | 220 | FILE *fp_bmp; |
smorioka | 0:f31ceb6058cb | 221 | unsigned char sort[3]; |
smorioka | 0:f31ceb6058cb | 222 | unsigned int buf_ptr = 0; |
smorioka | 0:f31ceb6058cb | 223 | |
smorioka | 0:f31ceb6058cb | 224 | led3 = 1; |
smorioka | 0:f31ceb6058cb | 225 | |
smorioka | 0:f31ceb6058cb | 226 | fp_bmp = fopen("/sd/cam.bmp", "wb"); |
smorioka | 0:f31ceb6058cb | 227 | |
smorioka | 0:f31ceb6058cb | 228 | ///////////////////////// |
smorioka | 0:f31ceb6058cb | 229 | // file header |
smorioka | 0:f31ceb6058cb | 230 | ///////////////////////// |
smorioka | 0:f31ceb6058cb | 231 | fprintf(fp_bmp, "BM"); |
smorioka | 0:f31ceb6058cb | 232 | int val = 14 + 40 + SIZEX * SIZEY * 3; // file size |
smorioka | 0:f31ceb6058cb | 233 | fprintf(fp_bmp, "%c%c%c%c", val % 0x100, val / 0x100, val / 0x10000, val / 0x1000000); |
smorioka | 0:f31ceb6058cb | 234 | fprintf(fp_bmp, "%c%c%c%c%c%c%c%c", 0, 0, 0, 0, 0x36, 0, 0, 0); |
smorioka | 0:f31ceb6058cb | 235 | |
smorioka | 0:f31ceb6058cb | 236 | ///////////////////////// |
smorioka | 0:f31ceb6058cb | 237 | // information header |
smorioka | 0:f31ceb6058cb | 238 | ///////////////////////// |
smorioka | 0:f31ceb6058cb | 239 | fprintf(fp_bmp, "%c%c%c%c", 0x28, 0, 0, 0); // header size |
smorioka | 0:f31ceb6058cb | 240 | fprintf(fp_bmp, "%c%c%c%c", SIZEX % 0x100, SIZEX / 0x100, SIZEX / 0x10000, SIZEX / 0x1000000); |
smorioka | 0:f31ceb6058cb | 241 | fprintf(fp_bmp, "%c%c%c%c", SIZEY % 0x100, SIZEY / 0x100, SIZEY / 0x10000, SIZEY / 0x1000000); |
smorioka | 0:f31ceb6058cb | 242 | fprintf(fp_bmp, "%c%c", 1, 0); // # of plane |
smorioka | 0:f31ceb6058cb | 243 | fprintf(fp_bmp, "%c%c", 24, 0); // bit count |
smorioka | 0:f31ceb6058cb | 244 | fprintf(fp_bmp, "%c%c%c%c", 0, 0, 0, 0); // compression |
smorioka | 0:f31ceb6058cb | 245 | val = SIZEX * SIZEY * 3; // data size |
smorioka | 0:f31ceb6058cb | 246 | fprintf(fp_bmp, "%c%c%c%c", val % 0x100, val / 0x100, val / 0x10000, val / 0x1000000); |
smorioka | 0:f31ceb6058cb | 247 | fprintf(fp_bmp, "%c%c%c%c", 0, 0, 0, 0); |
smorioka | 0:f31ceb6058cb | 248 | fprintf(fp_bmp, "%c%c%c%c", 0, 0, 0, 0); |
smorioka | 0:f31ceb6058cb | 249 | fprintf(fp_bmp, "%c%c%c%c", 0, 0, 0, 0); |
smorioka | 0:f31ceb6058cb | 250 | fprintf(fp_bmp, "%c%c%c%c", 0, 0, 0, 0); |
smorioka | 0:f31ceb6058cb | 251 | |
smorioka | 0:f31ceb6058cb | 252 | for (int y = 0;y < SIZEY;y++) { |
smorioka | 0:f31ceb6058cb | 253 | for (int x = 0;x < SIZEX;x++) { |
smorioka | 0:f31ceb6058cb | 254 | sort[0] = image_buf_g[buf_ptr++]; |
smorioka | 0:f31ceb6058cb | 255 | sort[1] = image_buf_g[buf_ptr++]; |
smorioka | 0:f31ceb6058cb | 256 | sort[2] = image_buf_g[buf_ptr++]; |
smorioka | 0:f31ceb6058cb | 257 | |
smorioka | 0:f31ceb6058cb | 258 | fprintf(fp_bmp, "%c%c%c", sort[2], sort[1], sort[0]); // B,G,R |
smorioka | 0:f31ceb6058cb | 259 | } |
smorioka | 0:f31ceb6058cb | 260 | } |
smorioka | 0:f31ceb6058cb | 261 | |
smorioka | 0:f31ceb6058cb | 262 | fclose(fp_bmp); |
smorioka | 0:f31ceb6058cb | 263 | |
smorioka | 0:f31ceb6058cb | 264 | led3 = 0; |
smorioka | 0:f31ceb6058cb | 265 | } |
smorioka | 0:f31ceb6058cb | 266 | |
smorioka | 0:f31ceb6058cb | 267 | //void cam_cap(Arguments* input, Reply* output) |
smorioka | 0:f31ceb6058cb | 268 | void cam_cap(void) |
smorioka | 0:f31ceb6058cb | 269 | { |
smorioka | 0:f31ceb6058cb | 270 | unsigned int d1, d2; |
smorioka | 0:f31ceb6058cb | 271 | unsigned char sort[3]; |
smorioka | 0:f31ceb6058cb | 272 | unsigned int buf_ptr = 0; |
smorioka | 0:f31ceb6058cb | 273 | |
smorioka | 0:f31ceb6058cb | 274 | led2 = 1; |
smorioka | 0:f31ceb6058cb | 275 | |
smorioka | 0:f31ceb6058cb | 276 | camera.CaptureNext(); // sample start! |
smorioka | 0:f31ceb6058cb | 277 | |
smorioka | 0:f31ceb6058cb | 278 | while(camera.CaptureDone() == false) |
smorioka | 0:f31ceb6058cb | 279 | ; |
smorioka | 0:f31ceb6058cb | 280 | |
smorioka | 0:f31ceb6058cb | 281 | camera.ReadStart(); // reset pointer |
smorioka | 0:f31ceb6058cb | 282 | |
smorioka | 0:f31ceb6058cb | 283 | for (int y = 0;y < SIZEY;y++) { |
smorioka | 0:f31ceb6058cb | 284 | for (int x = 0;x < SIZEX;x++) { |
smorioka | 0:f31ceb6058cb | 285 | d1 = camera.ReadOneByte() ; // upper nibble is XXX , lower nibble is B |
smorioka | 0:f31ceb6058cb | 286 | d2 = camera.ReadOneByte() ; // upper nibble is G , lower nibble is R |
smorioka | 0:f31ceb6058cb | 287 | |
smorioka | 0:f31ceb6058cb | 288 | // RGB565 to RGB888 |
smorioka | 0:f31ceb6058cb | 289 | sort[0] = ((d1 & 0xF8) >> 3) << 3; // R |
smorioka | 0:f31ceb6058cb | 290 | sort[1] = ( ((d1 & 0x07) << 3) + ((d2 & 0xE0) >> 5) ) << 2; // G |
smorioka | 0:f31ceb6058cb | 291 | sort[2] = (d2 & 0x1F) << 3; // B |
smorioka | 0:f31ceb6058cb | 292 | |
smorioka | 0:f31ceb6058cb | 293 | image_buf_g[buf_ptr++] = sort[2]; |
smorioka | 0:f31ceb6058cb | 294 | image_buf_g[buf_ptr++] = sort[1]; |
smorioka | 0:f31ceb6058cb | 295 | image_buf_g[buf_ptr++] = sort[0]; |
smorioka | 0:f31ceb6058cb | 296 | } |
smorioka | 0:f31ceb6058cb | 297 | } |
smorioka | 0:f31ceb6058cb | 298 | |
smorioka | 0:f31ceb6058cb | 299 | camera.ReadStop(); |
smorioka | 0:f31ceb6058cb | 300 | |
smorioka | 0:f31ceb6058cb | 301 | led2 = 0; |
smorioka | 0:f31ceb6058cb | 302 | } |
smorioka | 0:f31ceb6058cb | 303 | |
smorioka | 0:f31ceb6058cb | 304 | // end of file |