おまけ:RICOH THETAのJPG画像を平面-球変換してOpenGLで表示する(その3)
(編集中)
このページで紹介されている加速度情報の取得のC++翻訳版、とりあえずWindowsで動けば良いや編。あとで整理するかも。*1
http://d.hatena.ne.jp/xanxys/20131110/1384094832
#include <fstream>
ifstream fin;
unsigned char head[10*1000];
union {
int i;
unsigned int ui;
unsigned char b[4];
} bytes;
fin.open("R0010071.JPG", ios::in | ios::binary);
fin.read((char*)head,10*1000);
for(int i=0; i<10*1000; i++){
unsigned char *buf = head + i;
if(buf[0] == 0x00 && buf[1] == 0x04 && buf[2] == 0x00 && buf[3] == 0x05 && buf[4] == 0x00 && buf[5] == 0x00 && buf[6] == 0x00 && buf[7] == 0x01) {
printf("compassEs found in %d\n", i);
// big endian to little endian
bytes.b[0] = buf[3+8];
bytes.b[1] = buf[2+8];
bytes.b[2] = buf[1+8];
bytes.b[3] = buf[0+8];
unsigned int offset = bytes.ui + 12;
printf("offset %d\n", offset);
bytes.b[0] = head[offset+3];
bytes.b[1] = head[offset+2];
bytes.b[2] = head[offset+1];
bytes.b[3] = head[offset+0];
unsigned int a = bytes.ui;
bytes.b[0] = head[offset+7];
bytes.b[1] = head[offset+6];
bytes.b[2] = head[offset+5];
bytes.b[3] = head[offset+4];
unsigned int b = bytes.ui;
float compass = (float)a / (float)b;
printf("compass = %f %d %d\n", compass, a, b);
}
}
for(int i=0; i<10*1000; i++){
unsigned char *buf = head + i;
if(buf[0] == 0x00 && buf[1] == 0x03 && buf[2] == 0x00 && buf[3] == 0x0a && buf[4] == 0x00 && buf[5] == 0x00 && buf[6] == 0x00 && buf[7] == 0x02) {
printf("zenithEs found in %d\n", i);
// big endian to little endian
bytes.b[0] = buf[3+8];
bytes.b[1] = buf[2+8];
bytes.b[2] = buf[1+8];
bytes.b[3] = buf[0+8];
unsigned int offset = bytes.ui + 12;
printf("offset %d\n", offset);
bytes.b[0] = head[offset+3];
bytes.b[1] = head[offset+2];
bytes.b[2] = head[offset+1];
bytes.b[3] = head[offset+0];
int a = bytes.i;
bytes.b[0] = head[offset+7];
bytes.b[1] = head[offset+6];
bytes.b[2] = head[offset+5];
bytes.b[3] = head[offset+4];
int b = bytes.i;
float zenith_x = (float)a / (float)b;
printf("zenith_x = %f %d %d\n", zenith_x, a, b);
bytes.b[0] = head[offset+3+8];
bytes.b[1] = head[offset+2+8];
bytes.b[2] = head[offset+1+8];
bytes.b[3] = head[offset+0+8];
a = bytes.i;
bytes.b[0] = head[offset+7+8];
bytes.b[1] = head[offset+6+8];
bytes.b[2] = head[offset+5+8];
bytes.b[3] = head[offset+4+8];
b = bytes.i;
float zenith_y = (float)a / (float)b;
printf("zenith_y = %f %d %d\n", zenith_y, a, b);
break;
}
}
fin.close();
*1:ファイルによってはcompassEs情報が見つからないことがあるようです。