Skip to content

Commit

Permalink
* ignore csv log comments
Browse files Browse the repository at this point in the history
  • Loading branch information
backface committed Jan 6, 2012
1 parent f1efdb3 commit cabf262
Show file tree
Hide file tree
Showing 3 changed files with 196 additions and 51 deletions.
141 changes: 136 additions & 5 deletions linescan.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ int flag_watcher_mode = 0;
int flag_prescanned=0;
int flag_downscale=1;
int flag_jp4 = 0;
int flag_calib = 0;

int waiting_eos = 0;

Expand All @@ -143,6 +144,7 @@ struct confopt {
struct confopt confopt[] = {
{ "verbose", co_bool, { .pc_int = &flag_verbose } },
{ "jp4out", co_bool, { .pc_int = &flag_jp4 } },
{ "calib", co_bool, { .pc_int = &flag_calib } },
{ "dropframes", co_int, { .pc_int = &flag_dropframes } },
{ "bufferheight", co_int, { .pc_int = &buf_height } },
{ "lineheight", co_int, { .pc_int = &line_height } },
Expand Down Expand Up @@ -272,6 +274,7 @@ void read_options(int argc, char *argv[]) {
{"verbose", no_argument, &flag_verbose, 1},
{"brief", no_argument, &flag_verbose, 0},
{"display", no_argument, &flag_display, 1},
{"calib", no_argument, &flag_calib, 1},
{"jp4", no_argument, &flag_jp4, 1},
{"watch", no_argument, &flag_watcher_mode, 1},
{"nodisplay", no_argument, &flag_display, 0},
Expand Down Expand Up @@ -352,6 +355,7 @@ void read_options(int argc, char *argv[]) {
printf(" --jp4 jp4 mode (Elphel raw)\n");
printf(" --nodisplay run without preview\n");
printf(" --no-downscale(NOT YET) no downscale image for preview (slower and BROKEN!)\n");
printf(" --calib (NOT YET!) Use calibration (darkframe substraction and flatframe)\n");
printf(" --watch watcher mode (use intofiy to watch a directory)\n");
printf(" -i | --watch-dir directory to watch\n");
printf(" --watch-src-cmd command to launch for watching mode\n");
Expand Down Expand Up @@ -433,10 +437,10 @@ void gps_setup()
logfilename);
}
else {
fprintf(gpslog_file,"frame/tile, UTC, mode, \
latitude, longitude, altitude, \
speed, distance, track, climb, epx, epy, epv, \
satellites_visible, satellites_used\n");
fprintf(gpslog_file,"#frame/tile; UTC; mode; \
latitude; longitude; altitude; \
speed; distance; track; climb; epx; epy; epv; \
satellites_visible; satellites_used\n");
}
}
gps_clear_fix(&gpsfix);
Expand Down Expand Up @@ -848,6 +852,9 @@ void on_key_up(unsigned char key, int x, int y) {
else if (key == 'g') {
draw_grey = !draw_grey;
}
else if (key == 'c') {
flag_calib = !flag_calib;
}
else if (key == 'q') {
waiting_eos = 1;
}
Expand Down Expand Up @@ -973,6 +980,115 @@ void write_movie_start(IplImage *frame)
//CV_FOURCC('I', '4', '2', '0'), 100, imgSize, 1);
}

void calibration_apply(IplImage *image)
{
IplImage* tmpimg;
tmpimg = cvCloneImage(image);

// substract darframe
if (darkframe) {
if (darkframe->height != image->height || darkframe->width != image->width) {
printf("darkframe has wrong image size! Do not apply calibration images!\n");
flag_calib = 0;
}
else
cvSub(image, darkframe, image,NULL);
}

// divide by flatframe
if (flatframe) {
if (flatframe->height != image->height || flatframe->width != image->width) {
printf("flatframe has wrong image size! Do not apply calibration images!\n");
flag_calib = 0;
}
else
cvDiv(tmpimg, flatframe, image, 150);
}

/*
for(i = 0; i < last_full_frame->height; i++) {
for(x = 0; x < last_full_frame->width; x++) {
//printf("%d",(flatframe->imageData + i * flatframe->widthStep)[x * flatframe->nChannels + 1] );
//printf(" %d",(last_full_frame->imageData + i * last_full_frame->widthStep)[x * last_full_frame->nChannels + 1] );
if ((flatframe->imageData + i * flatframe->widthStep)[x * flatframe->nChannels + 0] != 0)
((uchar *)(last_full_frame->imageData + i * last_full_frame->widthStep))[x * last_full_frame->nChannels + 0] *=
255/ ((uchar *)(flatframe->imageData + i * flatframe->widthStep))[x * flatframe->nChannels + 0];
if ((flatframe->imageData + i * flatframe->widthStep)[x * flatframe->nChannels + 1] != 0)
((uchar *)(last_full_frame->imageData + i * last_full_frame->widthStep))[x * last_full_frame->nChannels + 1] *=
255/ ((uchar*)(flatframe->imageData + i * flatframe->widthStep))[x * flatframe->nChannels + 1];
if ((flatframe->imageData + i * flatframe->widthStep)[x * flatframe->nChannels + 2] != 0)
((uchar *)(last_full_frame->imageData + i * last_full_frame->widthStep))[x * last_full_frame->nChannels + 2] *=
255/ ((uchar *)(flatframe->imageData + i * flatframe->widthStep))[x * flatframe->nChannels + 2];
}
}
*/
}

// not yet working
void calibration_loadimages()
{
// load darkframe
darkframe = cvLoadImage("calibration/darkframe.jpg", 3);
if (!darkframe) {
printf("Could not load darkframe.jpg");
exit(1);
}

flatframe = cvLoadImage("calibration/flatframe.jpg", 3);

// load flatframe
if (!flatframe) {
printf("Could not load flatframe.jpg");
exit(1);
} else {
IplImage *flat_normalized = cvCreateImage ( cvSize(flatframe->width,flatframe->height), IPL_DEPTH_8U, 1) ;
int i, x;

// find maxima
for(i = 0; i < flatframe->height; i++) {
for(x = 0; x < flatframe->width; x++) {
if ((flatframe->imageData + i * flatframe->widthStep)[x * flatframe->nChannels + 0] > max_b)
max_b = (flatframe->imageData + i * flatframe->widthStep)[x * flatframe->nChannels + 0];

if ((flatframe->imageData + i * flatframe->widthStep)[x * flatframe->nChannels + 1] > max_g)
max_g = (flatframe->imageData + i * flatframe->widthStep)[x * flatframe->nChannels + 1];

if ((flatframe->imageData + i * flatframe->widthStep)[x * flatframe->nChannels + 2] > max_r)
max_r = (flatframe->imageData + i * flatframe->widthStep)[x * flatframe->nChannels + 2];

if ((flatframe->imageData + i * flatframe->widthStep)[x * flatframe->nChannels + 0] > max)
max = (flatframe->imageData + i * flatframe->widthStep)[x * flatframe->nChannels + 0];

if ((flatframe->imageData + i * flatframe->widthStep)[x * flatframe->nChannels + 1] > max)
max = (flatframe->imageData + i * flatframe->widthStep)[x * flatframe->nChannels + 1];

if ((flatframe->imageData + i * flatframe->widthStep)[x * flatframe->nChannels + 2] > max)
max = (flatframe->imageData + i * flatframe->widthStep)[x * flatframe->nChannels + 2];
}
}

// normalize

for(i = 0; i < flatframe->height; i++) {
for(x = 0; x < flatframe->width; x++) {

((uchar *)(flatframe->imageData + i * flatframe->widthStep))[x * flatframe->nChannels + 0] *= 255 /max_g;
((uchar *)(flatframe->imageData + i * flatframe->widthStep))[x * flatframe->nChannels + 1] *= 255 /max_g;
((uchar *)(flatframe->imageData + i * flatframe->widthStep))[x * flatframe->nChannels + 2] *= 255 /max_r;

}
}

//cvShowImage("wind",flatframe);
//cvSub(flatframe,darkframe,flatframe,NULL);
}
}



static void process_buffer (GstElement *sink) {
int i, j, x, y;
int r = 0;
Expand Down Expand Up @@ -1042,6 +1158,10 @@ static void process_buffer (GstElement *sink) {
//last_full_frame->imageData = GST_BUFFER_DATA(buffer);
}

if (flag_calib) {
calibration_apply(last_full_frame);
}

if ( (!writer || last_full_frame->width != width) && flag_write_movie) {
write_movie_start(last_full_frame);

Expand Down Expand Up @@ -1079,6 +1199,10 @@ static void process_buffer (GstElement *sink) {
clear_frame(frame);
}

if (flag_calib) {
calibration_apply(frame);
}

if ( (!writer || frame->width != width) && flag_write_movie) {
write_movie_start(frame);
}
Expand Down Expand Up @@ -1323,6 +1447,9 @@ int inotify_watch()
clear_frame(frame);
}

if (flag_calib)
calibration_apply(last_full_frame);

if ( (!writer) && flag_write_movie) {
write_movie_start(last_full_frame);
}
Expand Down Expand Up @@ -1561,7 +1688,11 @@ gint main (gint argc, gchar *argv[]) {
printf("GStreamer: pipline playing.\n");
}

int result;
if (flag_calib) {
calibration_loadimages();
}

int result;
// init viewer thread
if (flag_display) {
result = pthread_mutex_init(&frame_mutex, NULL);
Expand Down
78 changes: 43 additions & 35 deletions tools/generate_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
name = "test"
th_height = 128
process_logs = True
process_images = True
process_html = True
verbose = True
trackfile = "track.gpx"
tracklogfile = "track.log.csv"
Expand All @@ -44,8 +46,8 @@ def process_args():
global input, output, format, name, process_logs

try:
opts, args = getopt.getopt(sys.argv[1:], "hi:o:n",
["help", "input=","output=","name=","nologs"])
opts, args = getopt.getopt(sys.argv[1:], "hi:o:nl",
["help", "input=","output=","name=","nologs","log-only"])
except getopt.GetoptError, err:
# print help information and exit:
print str(err) # will print something like "option -a not recognized"
Expand All @@ -68,6 +70,10 @@ def process_args():
name = a
elif o in ("-n","--nologs"):
process_logs = False
elif o in ("-l","--logs-only"):
process_logs = True
process_images = False
process_html = False
else:
assert False, "unhandled option"

Expand Down Expand Up @@ -104,11 +110,13 @@ def process_args():

thumb_file = "%s/%s" % (thumb_path,os.path.basename(file))
log_file = "%s.log" % file
img = Image.open(file)
w = img.size[0]
h = img.size[1]
ratio = th_height / float(h)
th_width = int(w * ratio)

if process_images:
img = Image.open(file)
w = img.size[0]
h = img.size[1]
ratio = th_height / float(h)
th_width = int(w * ratio)

if process_logs:
if os.path.exists(file + ".log"):
Expand All @@ -132,17 +140,17 @@ def process_args():
except:
print "x"

if not os.path.exists(thumb_file):
if not os.path.exists(thumb_file) and process_images:
# generate thumbs
if verbose:
print "make thumnail from %s" % os.path.basename(file)
img_out = img.resize((th_width,th_height),Image.ANTIALIAS)
createPath(thumb_file)
img_out.save(thumb_file)


source += '<a href="%s"><img border="0" src="%s" alt="" height="%d" width="%d" /></a>\n' % \
(file, thumb_file, th_height, th_width)
if process_html:
source += '<a href="%s"><img border="0" src="%s" alt="" height="%d" width="%d" /></a>\n' % \
(file, thumb_file, th_height, th_width)

count+=1

Expand All @@ -156,27 +164,27 @@ def process_args():

# now write to files
print "%d files found." % count
print "generating html.."


# write html
f = open(html_file, 'w')
f.write('''<html>
<head>
<title>%s</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<style type="text/css" media="screen">
body {font-family: Georgia, Times New Roman, Times, serif}
a {padding:0px;margin:0px}
img {padding:0px;margin:0px;margin-right:-4px;margin-top:5px}
</style>
<head>
<body>
<h2>%s</h2>
<div id="info">%s</div>
<div id="thumbs">
%s
</div>
</html>''' % ( name, name, info, source )
)
f.close()
if process_html:
print "generating html.."

# write html
f = open(html_file, 'w')
f.write('''<html>
<head>
<title>%s</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<style type="text/css" media="screen">
body {font-family: Georgia, Times New Roman, Times, serif}
a {padding:0px;margin:0px}
img {padding:0px;margin:0px;margin-right:-4px;margin-top:5px}
</style>
<head>
<body>
<h2>%s</h2>
<div id="info">%s</div>
<div id="thumbs">
%s
</div>
</html>''' % ( name, name, info, source )
)
f.close()
Loading

0 comments on commit cabf262

Please sign in to comment.