From 67e0d160afa8ebdeb4354292cebc038571a91531 Mon Sep 17 00:00:00 2001 From: Steffen Pohle Date: Sun, 25 Feb 2024 21:06:37 +0100 Subject: [PATCH] renaming filter to output... preparing raw output to save --- Makefile | 2 +- detect.cc | 16 +++--- filter.cc | 120 ------------------------------------------- gui.cc | 18 +++---- main.cc | 4 +- output.cc | 93 +++++++++++++++++++++++++++++++++ filter.h => output.h | 15 +++--- pid.h | 2 + posctl.cc | 16 +++--- simpleskycam.ui | 77 --------------------------- video.cc | 2 +- videodev.cc | 2 +- 12 files changed, 130 insertions(+), 237 deletions(-) delete mode 100644 filter.cc create mode 100644 output.cc rename filter.h => output.h (85%) diff --git a/Makefile b/Makefile index 7c82a32..b8e0230 100644 --- a/Makefile +++ b/Makefile @@ -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) diff --git a/detect.cc b/detect.cc index 3df6d93..1df7ba5 100644 --- a/detect.cc +++ b/detect.cc @@ -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); } diff --git a/filter.cc b/filter.cc deleted file mode 100644 index 0b2e8d0..0000000 --- a/filter.cc +++ /dev/null @@ -1,120 +0,0 @@ - - -#include - -#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); - } - } -} - - diff --git a/gui.cc b/gui.cc index eadd1c9..af31462 100644 --- a/gui.cc +++ b/gui.cc @@ -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) { diff --git a/main.cc b/main.cc index 27cf320..d46dd04 100644 --- a/main.cc +++ b/main.cc @@ -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; diff --git a/output.cc b/output.cc new file mode 100644 index 0000000..d53b2cb --- /dev/null +++ b/output.cc @@ -0,0 +1,93 @@ + + +#include + +#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); +} + + diff --git a/filter.h b/output.h similarity index 85% rename from filter.h rename to output.h index ae67fbf..bb600c9 100644 --- a/filter.h +++ b/output.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 (); diff --git a/pid.h b/pid.h index 70c260b..05e19cd 100644 --- a/pid.h +++ b/pid.h @@ -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); diff --git a/posctl.cc b/posctl.cc index 3871828..28783ff 100644 --- a/posctl.cc +++ b/posctl.cc @@ -12,7 +12,6 @@ #include #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; diff --git a/simpleskycam.ui b/simpleskycam.ui index ff70451..2f0b37a 100644 --- a/simpleskycam.ui +++ b/simpleskycam.ui @@ -2508,81 +2508,4 @@ Image Data - - False - Output - 400 - 300 - - - - True - False - vertical - - - True - False - - - - - True - True - 0 - - - - - True - False - - - gtk-new - True - True - True - True - True - - - - - False - True - 0 - - - - - gtk-save - True - True - True - True - True - - - - - False - True - 6 - 1 - - - - - False - True - 4 - 1 - - - - - - - - diff --git a/video.cc b/video.cc index 3755372..d67df97 100644 --- a/video.cc +++ b/video.cc @@ -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" diff --git a/videodev.cc b/videodev.cc index 50e9b8d..ae0d00e 100644 --- a/videodev.cc +++ b/videodev.cc @@ -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; }