mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
Merge branch 'master' of https://github.com/iabdalkader/openmv into binupd_20130919
This commit is contained in:
commit
a1764a9194
@ -11,15 +11,34 @@
|
||||
#include "xalloc.h"
|
||||
#include "imlib.h"
|
||||
#include "mdefs.h"
|
||||
|
||||
#define BUF_LEN (1024*3)
|
||||
|
||||
#define R8(p) \
|
||||
(uint8_t)((p>>11) * 255/31)
|
||||
rb_tbl[((p>>3)&0x1F)]
|
||||
|
||||
#define G8(p) \
|
||||
(uint8_t)(((p>>5)&0x3F)* 255/63)
|
||||
g_tbl[((p&0x07)<<3)|(p>>13)]
|
||||
|
||||
#define B8(p) \
|
||||
(uint8_t)((p&0x1F) * 255/31)
|
||||
#define SWAP(x)\
|
||||
({ uint16_t _x = (x); \
|
||||
(((_x & 0xff)<<8 |(_x & 0xff00) >> 8));})
|
||||
rb_tbl[((p>>8)&0x1F)]
|
||||
|
||||
static uint8_t rb_tbl []= {
|
||||
0, 8, 16, 24, 32, 41, 49, 57, 65, 74,
|
||||
82, 90, 98, 106, 115, 123, 131, 139,
|
||||
148, 156, 164, 172, 180, 189, 197, 205,
|
||||
213, 222, 230, 238, 246, 255
|
||||
};
|
||||
|
||||
static uint8_t g_tbl []= {
|
||||
0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44,
|
||||
48, 52, 56, 60, 64, 68, 72, 76, 80, 85, 89,
|
||||
93, 97, 101, 105, 109, 113, 117, 121, 125, 129,
|
||||
133, 137, 141, 145, 149, 153, 157, 161, 165, 170,
|
||||
174, 178, 182, 186, 190, 194, 198, 202, 206, 210,
|
||||
214, 218, 222, 226, 230, 234, 238, 242, 246, 250, 255
|
||||
};
|
||||
|
||||
static int isspace(int c)
|
||||
{
|
||||
return (c=='\n'||c=='\r'||c=='\t'||c==' ');
|
||||
@ -60,6 +79,9 @@ int ppm_write(image_t *img, const char *path)
|
||||
UINT bytes;
|
||||
FRESULT res=FR_OK;
|
||||
|
||||
int idx=0;
|
||||
uint8_t buf[BUF_LEN];
|
||||
|
||||
res = f_open(&fp, path, FA_WRITE|FA_CREATE_ALWAYS);
|
||||
if (res != FR_OK) {
|
||||
return res;
|
||||
@ -79,19 +101,24 @@ int ppm_write(image_t *img, const char *path)
|
||||
if (img->bpp == 1) {
|
||||
res = f_write(&fp, img->data, img->w*img->h, &bytes);
|
||||
} else {
|
||||
uint8_t rgb[3];
|
||||
uint16_t *pixels = (uint16_t*)img->data;
|
||||
for (int j=0; j<img->h; j++) {
|
||||
for (int i=0; i<img->w; i++) {
|
||||
uint16_t c = SWAP(pixels[j*img->w+i]);
|
||||
rgb[0] = R8(c); rgb[1] = G8(c); rgb[2] = B8(c);
|
||||
res = f_write(&fp, rgb, 3, &bytes);
|
||||
if (res != FR_OK || bytes != 3) {
|
||||
for (int i=0; i<img->w*img->h; i++) {
|
||||
uint16_t p = pixels[i];
|
||||
buf[idx++]=R8(p); buf[idx++]=G8(p); buf[idx++]=B8(p); //RGB565->RGB888
|
||||
if (idx == BUF_LEN) {
|
||||
idx = 0;
|
||||
res = f_write(&fp, buf, BUF_LEN, &bytes);
|
||||
if (res != FR_OK || bytes != BUF_LEN) {
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (idx) {
|
||||
res = f_write(&fp, buf, idx, &bytes);
|
||||
if (res != FR_OK || bytes != idx) {
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
error:
|
||||
@ -167,6 +194,9 @@ int ppm_write_subimg(image_t *img, const char *path, rectangle_t *r)
|
||||
UINT bytes;
|
||||
FRESULT res=FR_OK;
|
||||
|
||||
int idx=0;
|
||||
uint8_t buf[BUF_LEN];
|
||||
|
||||
res = f_open(&fp, path, FA_WRITE|FA_CREATE_ALWAYS);
|
||||
if (res != FR_OK) {
|
||||
return res;
|
||||
@ -194,19 +224,27 @@ int ppm_write_subimg(image_t *img, const char *path, rectangle_t *r)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
uint8_t rgb[3];
|
||||
uint16_t *pixels = (uint16_t*)img->data;
|
||||
for (int j=r->y; j<r->y+r->h; j++) {
|
||||
for (int i=r->x; i<r->x+r->w; i++) {
|
||||
uint16_t c = SWAP(pixels[j*img->w+i]);
|
||||
rgb[0] = R8(c); rgb[1] = G8(c); rgb[2] = B8(c);
|
||||
res = f_write(&fp, rgb, 3, &bytes);
|
||||
if (res != FR_OK || bytes != 3) {
|
||||
goto error;
|
||||
uint16_t p = pixels[j*img->w+i];
|
||||
buf[idx++]=R8(p); buf[idx++]=G8(p); buf[idx++]=B8(p); //RGB565->RGB888
|
||||
if (idx == BUF_LEN) {
|
||||
idx = 0;
|
||||
res = f_write(&fp, buf, BUF_LEN, &bytes);
|
||||
if (res != FR_OK || bytes != BUF_LEN) {
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (idx) {
|
||||
res = f_write(&fp, buf, idx, &bytes);
|
||||
if (res != FR_OK || bytes != idx) {
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
error:
|
||||
|
||||
@ -13,6 +13,5 @@ clock.tick()
|
||||
img = image.compress(30)
|
||||
print(clock.avg())
|
||||
|
||||
f = open("/test.jpeg", "w")
|
||||
f.write(img)
|
||||
f.close()
|
||||
with open("/test.jpeg", "w") as f:
|
||||
f.write(img)
|
||||
@ -1,3 +1,9 @@
|
||||
import sensor, time
|
||||
sensor.set_framesize(sensor.QCIF)
|
||||
sensor.set_pixformat(sensor.GRAYSCALE)
|
||||
sensor.snapshot().median(size=3)
|
||||
clock = time.clock()
|
||||
while (True):
|
||||
image = sensor.snapshot()
|
||||
clock.tick()
|
||||
image.median(size = 3)
|
||||
print(clock.fps())
|
||||
|
||||
@ -1,9 +0,0 @@
|
||||
import sensor, time
|
||||
sensor.set_framesize(sensor.VGA)
|
||||
sensor.set_pixformat(sensor.JPEG)
|
||||
sensor.set_quality (98)
|
||||
|
||||
image = sensor.snapshot()
|
||||
f = open("1:/test.jpeg", "wb")
|
||||
f.write(image)
|
||||
f.close()
|
||||
11
usr/examples/write_jpeg.py
Normal file
11
usr/examples/write_jpeg.py
Normal file
@ -0,0 +1,11 @@
|
||||
import sensor
|
||||
sensor.set_contrast(1)
|
||||
sensor.set_gainceiling(8)
|
||||
|
||||
sensor.set_framesize(sensor.QVGA)
|
||||
sensor.set_pixformat(sensor.JPEG)
|
||||
sensor.set_quality (98)
|
||||
|
||||
with open("/test.jpeg", "w") as f:
|
||||
f.write(sensor.snapshot())
|
||||
|
||||
8
usr/examples/write_ppm.py
Normal file
8
usr/examples/write_ppm.py
Normal file
@ -0,0 +1,8 @@
|
||||
import sensor
|
||||
sensor.set_contrast(1)
|
||||
sensor.set_gainceiling(8)
|
||||
sensor.set_framesize(sensor.QQVGA)
|
||||
sensor.set_pixformat(sensor.RGB565)
|
||||
|
||||
image = sensor.snapshot()
|
||||
image.save("/test.ppm")
|
||||
24
util/encode_raw.py
Executable file
24
util/encode_raw.py
Executable file
@ -0,0 +1,24 @@
|
||||
#!/usr/bin/env python
|
||||
# Converts raw RGB565 video to MP4/AVI
|
||||
|
||||
from sys import argv, exit
|
||||
from array import array
|
||||
from subprocess import call
|
||||
|
||||
buf=None
|
||||
TMP_FILE = "/tmp/video.raw"
|
||||
|
||||
if (len(argv) != 4):
|
||||
print("Usage: encode_raw input.raw output.avi fps")
|
||||
exit(1)
|
||||
|
||||
with open(argv[1], "rb") as f:
|
||||
buf = array("H", f.read())
|
||||
|
||||
#Swap not needed if rgb565be is supported
|
||||
buf.byteswap()
|
||||
with open(TMP_FILE, "wb") as f:
|
||||
f.write(buf.tostring())
|
||||
|
||||
cmd = "ffmpeg -vcodec rawvideo -r %d -f rawvideo -pix_fmt rgb565 -s 160x120 -i %s -vcodec mpeg4 %s"%(int(argv[3]), TMP_FILE, argv[2])
|
||||
call(cmd.split())
|
||||
Loading…
Reference in New Issue
Block a user