renaming filter to output... preparing raw output to save

master
Steffen Pohle 2 years ago
parent 5ac24490d3
commit 67e0d160af

@ -13,7 +13,7 @@ APP = simpleskycam
OBJECTS := $(OBJECTS) gui.oo main.oo error.oo debug.oo \
video.oo videoframe.oo \
videodev.oo videodev-dumpfile.oo videodev-simulation.oo \
convert.oo filter.oo detect.oo histogram.oo pid.oo \
convert.oo output.oo detect.oo histogram.oo pid.oo \
posctl.oo json.oo configuration.oo debayer.oo
DISTNAME=simpleskycam-$(VERSION)

@ -74,12 +74,12 @@ int Detect::NewFrame(VideoFrame *newframe) {
// NewFrame: will set new frame
// Thread: newFrame |------> Find Object --- not found ---> send gui information
void Detect::Thread() {
DetectOutput output;
DetectOutput doutput;
int oldX, oldY;
objectX = -1;
objectY = -1;
output.detmatrix = (uint32_t*)malloc (sizeof(uint32_t) * DET_MAXSHIFT * DET_MAXSHIFT);
doutput.detmatrix = (uint32_t*)malloc (sizeof(uint32_t) * DET_MAXSHIFT * DET_MAXSHIFT);
while (running) {
// check for new frame
@ -135,24 +135,24 @@ void Detect::Thread() {
imagegtk.CopyFrom(&image);
UnLockImageMutex();
output.posx = objectX;
output.posy = objectY;
output.image = &imagegtk;
doutput.posx = objectX;
doutput.posy = objectY;
doutput.image = &imagegtk;
if (detmatrix != NULL)
memcpy (output.detmatrix, detmatrix, sizeof(uint32_t) * DET_MAXSHIFT * DET_MAXSHIFT);
memcpy (doutput.detmatrix, detmatrix, sizeof(uint32_t) * DET_MAXSHIFT * DET_MAXSHIFT);
posctl.Loop (objectX, objectY);
UnLockMutex(); // unlock detect dataset
gdk_threads_add_idle(cb_thread_detect , &output);
gdk_threads_add_idle(cb_thread_detect , &doutput);
}
else
UnLockInMutex();
usleep (10000); // FIXME:: why is it here?
}
free (output.detmatrix);
free (doutput.detmatrix);
}

@ -1,120 +0,0 @@
#include <unistd.h>
#include "config.h"
#include "gui.h"
#include "filter.h"
extern Filter filter;
//gboolean cb_filtertemp_thread (gpointer data);
//gboolean cb_filterout_thread (gpointer data);
//
// C / C++ Wrapper for the thread function
//
gpointer _FilterThread (gpointer data) {
filter.Thread ();
return NULL;
};
Filter::Filter() { // @suppress("Class members should be properly initialized")
printf ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__);
g_mutex_init (&mutexin);
g_mutex_init (&muteximage);
g_mutex_init (&mutextmp);
g_mutex_init (&mutex);
running = 1;
inFrame.SetSize(64, 64);
image.SetSize(64, 64);
imagegtk.SetSize(64, 64);
thread = NULL;
thread = g_thread_new("Filter", _FilterThread, NULL);
};
Filter::~Filter() {
running = 0;
if (thread) {
g_thread_join (thread);
thread = NULL;
}
};
int Filter::NewFrame(VideoFrame *newframe, int posx, int posy) {
if (newframe == NULL) return -1;
LockInMutex();
inFrame.CopyFrom(newframe);
inFrameNew = 1;
UnLockInMutex();
return 0;
};
void Filter::NewImage() {
newimage = 1;
}
//
// NewFrame: will set new frame
// Thread: newFrame |------> Find Object --- not found ---> send gui information
void Filter::Thread() {
while (running) {
// check for new frame
LockInMutex();
if (inFrameNew == 1) {
inFrameNew = 0;
//
// do some other stuff use if possible only the oldFrame data
ComposeOutput();
UnLockInMutex();
// copy output image for gtk
LockImageMutex();
imagegtk.CopyFrom(&image);
UnLockImageMutex();
gdk_threads_add_idle(cb_thread_filter , &imagegtk);
}
else
UnLockInMutex();
usleep (10000);
}
}
#define FACTOR 25.0
void Filter::ComposeOutput() {
int x, y, idx, i;
float *pixd = NULL; // destination
unsigned char *pixs = NULL; // source
image.SetSize(inFrame.w, inFrame.h);
pixd = image.data;
pixs = inFrame.data;
if (pixd == NULL || pixs == NULL) return;
if (newimage) {
inFrame.CopyTo(&image);
newimage = 0;
}
else {
for (x = 0; x < inFrame.w; x++)
for (y = 0; y < inFrame.h; y++) {
idx = 3 * (inFrame.w * y + x);
for (i = 0; i < 3; i++)
pixd[idx+i] = ((FACTOR-1.0) * (float)pixd[idx+i]/FACTOR) + (float)(pixs[idx+i] / FACTOR);
}
}
}

@ -14,12 +14,12 @@
#include "gui.h"
#include "config.h"
#include "video.h"
#include "filter.h"
#include "output.h"
#include "detect.h"
#include "configuration.h"
extern GtkBuilder *_builder_; // work around for threads
extern Filter filter;
extern Output output;
extern Detect detect;
//
@ -105,7 +105,7 @@ gboolean cb_thread_filter (gpointer data) {
return false;
}
filter.LockImageMutex();
output.LockImageMutex();
if (image_pixbuf) {
pix_h = gdk_pixbuf_get_height(image_pixbuf);
@ -124,7 +124,7 @@ gboolean cb_thread_filter (gpointer data) {
vf->ToPixbuf(image_pixbuf);
gdk_window_invalidate_rect(gtk_widget_get_window(image_da), NULL, true);
filter.UnLockImageMutex();
output.UnLockImageMutex();
return false;
};
@ -168,7 +168,7 @@ gboolean cb_thread_detect (gpointer data) {
}
dout->image->ToPixbuf(detect_pixbuf);
gdk_window_invalidate_rect(gtk_widget_get_window(detect_da), NULL, true);
filter.NewFrame(dout->image, dout->posx, dout->posy);
output.NewFrame(dout->image, dout->posx, dout->posy);
detect.UnLockImageMutex();
@ -249,12 +249,9 @@ void cb_detect_btnsetsize (GtkWidget *widget, gpointer data) {
};
void cb_image_btnnew (GtkWidget *widget, gpointer data) {
filter.NewImage();
};
void cb_image_btnsave (GtkWidget *widget, gpointer data) {
/*
void cb_output_btnsave (GtkWidget *widget, gpointer data) {
GtkBuilder *builder = (GtkBuilder *) data;
GtkWindow *window = GTK_WINDOW (gtk_builder_get_object (builder, "window-main"));
GtkWidget *dialog;
@ -303,6 +300,7 @@ void cb_image_btnsave (GtkWidget *widget, gpointer data) {
gtk_widget_destroy (dialog);
};
*/
void cb_detect_bright (GtkRange *range, gpointer data) {

@ -11,7 +11,7 @@
#include "config.h"
#include "configuration.h"
#include "gui.h"
#include "filter.h"
#include "output.h"
#include "detect.h"
#include "convert.h"
@ -20,7 +20,7 @@
**************************************************************************/
GtkBuilder *_builder_ = NULL; // work around for the thread situation
Filter filter;
Output output;
Detect detect;
Configuration config;
PosCtl posctl;

@ -0,0 +1,93 @@
#include <unistd.h>
#include "config.h"
#include "gui.h"
#include "output.h"
extern Output output;
//
// C / C++ Wrapper for the thread function
//
gpointer _OutputThread (gpointer data) {
output.Thread ();
return NULL;
};
Output::Output() { // @suppress("Class members should be properly initialized")
printf ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__);
g_mutex_init (&mutexin);
g_mutex_init (&muteximage);
g_mutex_init (&mutextmp);
g_mutex_init (&mutex);
running = 1;
inFrame.SetSize(64, 64);
thread = NULL;
thread = g_thread_new("Output", _OutputThread, NULL);
};
Output::~Output() {
running = 0;
if (thread) {
g_thread_join (thread);
thread = NULL;
}
};
int Output::NewFrame(VideoFrame *newframe, int posx, int posy) {
if (newframe == NULL || posx == -1 || posy == -1) return -1;
// printf ("%s:%d Output::NewFrame Frame w:%d h:%d posx:%d posy:%d\n", __FILE__, __LINE__, newframe->w, newframe->h, posx, posy);
LockInMutex();
inFrame.CopyFrom(newframe);
inFrameNew = 1;
UnLockInMutex();
return 0;
};
void Output::NewImage() {
newimage = 1;
}
//
// NewFrame: will set new frame
// Thread: newFrame |------> Find Object --- not found ---> send gui information
void Output::Thread() {
while (running) {
// check for new frame
LockInMutex();
if (inFrameNew == 1) {
inFrameNew = 0;
//
// do some other stuff use if possible only the oldFrame data
ComposeOutput();
UnLockInMutex();
// copy output image for gtk
}
else
UnLockInMutex();
usleep (10000); // sleep 10ms
}
}
void Output::ComposeOutput() {
// printf ("%s:%d inFrame (w:%d h:%d)\n", __FILE__, __LINE__, inFrame.w, inFrame.h);
}

@ -1,12 +1,12 @@
/***************************************************************************************
*
* filter.h is part of SimpleSkyCam.
* output.h is part of SimpleSkyCam.
*
*****************************************************************************************/
#ifndef _FILTER_H_
#define _FILTER_H_
#ifndef _OUTPUT_H_
#define _OUTPUT_H_
#include "gui.h"
#include "config.h"
@ -14,27 +14,24 @@
#include "videoframe.h"
class Filter {
class Output {
private:
int running;
VideoFrame inFrame; // input frame
int inFrameNew; // new input frame;
FloatImage image; // detected image
VideoFrame imagegtk; // output image -- send to gtk
GMutex muteximage;
GMutex mutexin;
GMutex mutextmp; // for access the temp image
GMutex mutex; // general mutex for changing settings
GThread *thread;
float *fpixels; //
int newimage;
void ComposeOutput();
public:
Filter();
~Filter();
Output();
~Output();
int NewFrame (VideoFrame *newframe, int posx, int posy);
void NewImage ();

@ -20,6 +20,8 @@ class PID {
void Start(void);
void SetParam(double mi, double ma, double p, double i, double d);
void GetParam(double *mi, double *ma, double *p, double *i, double *d);
double GetMax() { return Max; };
double GetMin() { return Min; };
double Update(double target, double value, int64_t time);
double Update(double target, double value);
static int64_t GetTime(void);

@ -12,7 +12,6 @@
#include <math.h>
#include "gui.h"
#include "pid.h"
#include "filter.h"
#include "detect.h"
#include "configuration.h"
#include "video.h"
@ -59,9 +58,8 @@ void axis_history_add(int axis, double diff, double out) {
axis_history[axis][axis_history_pos[axis]].out = out;
}
#define CALIB_MAXSPEED 1.0
#define CALIB_DURATION_DELTA 5.0
#define CALIB_DURATION_AXIS (CALIB_DURATION_DELTA / CALIB_MAXSPEED)
#define CALIB_DURATION_DELTA 10.0
#define CALIB_DURATION_AXIS 10.0
void posctl_gui_update();
@ -611,6 +609,9 @@ void PosCtl::Stop() {
}
/*
* Start Calibration with the max axis output (a1, a2)
*/
void PosCtl::StartCalibration() {
printf ("%s:%d\n", __FILE__, __LINE__);
if (mode != POSCTL_MODE_OFF) {
@ -623,7 +624,6 @@ void PosCtl::StartCalibration() {
gdk_threads_add_idle(cb_thread_posctl, NULL);
}
void PosCtl::StartControl() {
if (mode != POSCTL_MODE_OFF) {
printf ("%s:%d mode is not off, can't start control.\n", __FILE__, __LINE__);
@ -660,7 +660,7 @@ void PosCtl::GetAxisParam ( int axis, double *min, double *max,
/*
* calibration functions
* calibration functionsdouble a1, double a2
*/
void PosCtl::CalibModeStart(int x, int y) {
printf ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__);
@ -701,7 +701,7 @@ void PosCtl::CalibModeDelta(int x, int y) {
calib_pos.x = x;
calib_pos.y = y;
if (OutputWriteValue(0, CALIB_MAXSPEED)) mode = POSCTL_MODE_OFF;
if (OutputWriteValue(0, pid_axis[0].GetMax())) mode = POSCTL_MODE_OFF;
gettimeofday (&calib_timestamp, NULL);
gdk_threads_add_idle(cb_thread_posctl, NULL);
@ -727,7 +727,7 @@ void PosCtl::CalibModeAxis(int x, int y) {
calib_axis1_v = fp - calib_rot_v;
calc_vec2anglelen(&calib_axis1_v, &calib_axis1);
if (OutputWriteStop()) mode = POSCTL_MODE_OFF;
else if (OutputWriteValue(1, CALIB_MAXSPEED)) mode = POSCTL_MODE_OFF;
else if (OutputWriteValue(1, pid_axis[1].GetMax())) mode = POSCTL_MODE_OFF;
}
else if (calib_mode == POSCTL_CALIB_MODE_AXIS2) {
calib_axis2_v = fp - calib_rot_v;

@ -2508,81 +2508,4 @@ Image Data</property>
</object>
</child>
</object>
<object class="GtkWindow" id="window-output">
<property name="can-focus">False</property>
<property name="title" translatable="yes">Output</property>
<property name="default-width">400</property>
<property name="default-height">300</property>
<signal name="delete-event" handler="gtk_widget_hide_on_delete" swapped="no"/>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkDrawingArea" id="image-da">
<property name="visible">True</property>
<property name="can-focus">False</property>
<signal name="draw" handler="cb_imagetempda_draw" swapped="no"/>
<signal name="motion-notify-event" handler="cb_videoda_motionevent" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkButton" id="btn-img-new">
<property name="label">gtk-new</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="use-stock">True</property>
<property name="always-show-image">True</property>
<signal name="activate" handler="cb_image_btnnew" swapped="no"/>
<signal name="pressed" handler="cb_image_btnnew" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="btn-img-save">
<property name="label">gtk-save</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="use-stock">True</property>
<property name="always-show-image">True</property>
<signal name="activate" handler="cb_image_btnsave" swapped="no"/>
<signal name="pressed" handler="cb_image_btnsave" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="padding">6</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="padding">4</property>
<property name="position">1</property>
</packing>
</child>
<child>
<placeholder/>
</child>
</object>
</child>
</object>
</interface>

@ -12,7 +12,7 @@
#include "config.h"
#include "gui.h"
#include "filter.h"
#include "output.h"
#include "detect.h"
#include "configuration.h"
#include "video.h"

@ -195,7 +195,7 @@ void VideoDev::ThreadProcess() {
cycle_time = get_cycletime(&cycle_timestamp);
cycle_wait = (CYCLETIME - cycle_time) + cycle_wait;
if (lastsec != cycle_timestamp.tv_sec) {
printf ("%s:%d %s Loop: cycle_time:%f Freq:%f Hz Frames:%d \r", __FILE__, __LINE__, __FUNCTION__, cycle_time, (1.0/cycle_time), numframes);
printf ("%s:%d %s Loop: cycle_time:%f Freq:%f Hz Frames:%d \n", __FILE__, __LINE__, __FUNCTION__, cycle_time, (1.0/cycle_time), numframes);
lastsec = cycle_timestamp.tv_sec;
numframes = 0;
}

Loading…
Cancel
Save