issues.. gui

test16bit
Steffen Pohle 4 years ago
parent c05a57c432
commit 608e546366

@ -39,7 +39,7 @@ Detect::Detect() { // @suppress("Class members should be properly initialized")
maxy = NULL;
detmatrix = NULL;
detmatrixv2 = NULL;
inputtype = 0;
autodetecttype = 2;
};
@ -85,35 +85,33 @@ void Detect::Thread() {
// object on the inFrame image.
// 2. check near the last known position.
switch (inputtype) {
switch (autodetecttype) {
case -1:
// no detection
break;
case 0:
InputDetect(&posx, &posy);
break;
case 1:
if (posx < objectW/2 || posy < objectH/2 ||
posx > (inFrame.w-objectW/2) || posy > (inFrame.h-objectH/2)) {
printf ("%s:%d %s find new position (last known:%d,%d)\n",
__FILE__, __LINE__, __FUNCTION__, posx, posy);
posx > (inFrame.w-objectW/2) || posy > (inFrame.h-objectH/2))
InputDetect(&posx, &posy);
}
else InputDetectCrossC(&posx, &posy);
break;
case 2:
if (posx < objectW/2 || posy < objectH/2 ||
posx > (inFrame.w-objectW/2) || posy > (inFrame.h-objectH/2)) {
printf ("%s:%d %s find new position (last known:%d,%d)\n",
__FILE__, __LINE__, __FUNCTION__, posx, posy);
posx > (inFrame.w-objectW/2) || posy > (inFrame.h-objectH/2))
InputDetect(&posx, &posy);
}
else InputDetectCrossCv2(&posx, &posy);
break;
default:
if (errorinputtype != inputtype)
printf ("%s:%d %s error: inputtype (%d) not found\n", __FILE__, __LINE__, __FUNCTION__, inputtype);
errorinputtype = inputtype;
if (errorinputtype != autodetecttype)
printf ("%s:%d %s error: autodetecttype (%d) not found\n", __FILE__, __LINE__, __FUNCTION__, autodetecttype);
errorinputtype = autodetecttype;
break;
}
@ -236,7 +234,7 @@ void Detect::InputDetect(int *posx, int *posy) {
#define OBJSIZE 50
#define MAXSHIFT 20
#define MAXSHIFT 40
// #define DEBUGTIMES 1
void Detect::InputDetectCrossC(int *posx, int *posy) {
unsigned char *pxi; // input image
@ -443,22 +441,52 @@ void Detect::InputDetectCrossCv2(int *posx, int *posy) {
void Detect::SetInputType(int intype) {
LockMutex();
inputtype = intype;
autodetecttype = intype;
UnLockMutex();
}
int Detect::GetInputType() {
int i;
LockMutex();
i = autodetecttype;
UnLockMutex();
return i;
}
//
// to set a new size we need to disable the detection for some moments.
// this will not setup any memory for te calculation buffers
void Detect::SetObjectSize(int neww, int newh) {
LockImageMutex();
LockInMutex();
int orgtype = autodetecttype;
// save detection type
LockMutex();
autodetecttype = -1;
UnLockMutex();
usleep (500000); // wait 0.5 sec
LockImageMutex();
objectH = newh;
objectW = neww;
UnLockImageMutex();
// restore orginal detection type
LockMutex();
autodetecttype = orgtype;
UnLockMutex();
}
void Detect::GetObjectSize (int *ow, int *oh) {
LockMutex();
*ow = objectW;
*oh = objectH;
UnLockMutex();
UnLockInMutex();
UnLockImageMutex();
}
@ -468,3 +496,17 @@ void Detect::SetMinBrightness(int value) {
UnLockMutex();
}
int Detect::GetMinBrightness() {
int i;
LockMutex();
i = minBright;
UnLockMutex();
return i;
}

@ -46,7 +46,7 @@ private:
int objectH; // object Image Size Height
int minBright; // min brightness
int inputtype; // input detection type to use
int autodetecttype; // input detection type to use
void InputDetect (int *posx, int *posy);
void InputDetectCrossC (int *posx, int *posy);
@ -75,8 +75,14 @@ public:
//
// Object functions
void SetObjectSize (int neww, int newh);
void GetObjectSize (int *ow, int *oh);
void SetMinBrightness (int value);
int GetMinBrightness();
void SetInputType(int intype);
int GetInputType();
void GetObjectPos (int *x, int *y);
void Thread();

@ -38,7 +38,9 @@ gboolean cb_window_delete_event (GtkWidget *widget, GdkEvent *event, gpointer
};
//
// setup default values
//
void cb_window_show (GtkWidget *widget, gpointer data) {
GtkWidget *btnstart = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "btn-video-rec"));
GtkWidget *btnstop = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "btn-video-stop"));
@ -50,9 +52,9 @@ void cb_window_show (GtkWidget *widget, gpointer data) {
gtk_widget_set_sensitive(btnstart, true);
gtk_widget_set_sensitive(btnstop, false);
gtk_entry_set_text(GTK_ENTRY(w),"600");
gtk_entry_set_text(GTK_ENTRY(h),"600");
detect.SetObjectSize(600, 600);
gtk_entry_set_text(GTK_ENTRY(w),"300");
gtk_entry_set_text(GTK_ENTRY(h),"300");
detect.SetObjectSize(300, 300);
g_timeout_add(2000, videoctrl_update, NULL);
};
@ -117,6 +119,8 @@ gboolean cb_thread_filter (gpointer data) {
// this is propabely the object detection
// Access to this data must be Locked before use and pointers must be looked to
gboolean cb_thread_detect (gpointer data) {
GtkWidget *e_x = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "detect-entry-posx"));
GtkWidget *e_y = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "detect-entry-posy"));
DetectOutput *dout = (DetectOutput *) data;
int pix_h, pix_w;
@ -126,6 +130,9 @@ gboolean cb_thread_detect (gpointer data) {
if (dout == NULL) return false;
if (dout->image == NULL) return false;
gtk_entry_set_text(GTK_ENTRY(e_x), std::to_string(dout->posx).c_str());
gtk_entry_set_text(GTK_ENTRY(e_y), std::to_string(dout->posy).c_str());
detect.LockImageMutex();
if (detect_pixbuf) {
@ -156,6 +163,7 @@ gboolean cb_thread_detect (gpointer data) {
void cb_imagetempda_draw(GtkWidget *area, cairo_t *cr, int w, int h, gpointer data) {
int clientw, clienth, pixbufw, pixbufh;
float clientar, pixbufar;
GdkRGBA color;
GdkPixbuf *pixbuf = NULL;
GdkPixbuf *src = NULL;
@ -183,13 +191,12 @@ void cb_imagetempda_draw(GtkWidget *area, cairo_t *cr, int w, int h, gpointer da
gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0);
cairo_paint(cr);
cairo_fill (cr);
g_object_unref (pixbuf);
};
void cb_detect_btnset (GtkWidget *widget, gpointer data) {
// GtkWidget *txtx = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "detect-entry-x"));
// GtkWidget *txty = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "detect-entry-y"));
void cb_detect_btnsetsize (GtkWidget *widget, gpointer data) {
GtkWidget *txtw = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "detect-entry-w"));
GtkWidget *txth = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "detect-entry-h"));

@ -63,7 +63,8 @@ G_MODULE_EXPORT void cb_detect_bright (GtkRange *range, gpointer data);
//
// detection elements
G_MODULE_EXPORT void cb_detect_btnset (GtkWidget *widget, gpointer data);
G_MODULE_EXPORT void cb_detect_btnsetpos (GtkWidget *widget, gpointer data);
G_MODULE_EXPORT void cb_detect_btnsetsize (GtkWidget *widget, gpointer data);
G_MODULE_EXPORT void cb_detect_inputtype (GtkWidget *widget, gpointer data);
#ifdef __cplusplus

@ -19,7 +19,7 @@
<object class="GtkPaned">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="position">800</property>
<property name="position">700</property>
<property name="position-set">True</property>
<property name="wide-handle">True</property>
<child>
@ -226,7 +226,7 @@
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<child>
<!-- n-columns=6 n-rows=2 -->
<!-- n-columns=7 n-rows=2 -->
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can-focus">False</property>
@ -292,7 +292,7 @@
</packing>
</child>
<child>
<object class="GtkEntry" id="detect-entry-x">
<object class="GtkEntry" id="detect-entry-posx">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="margin-left">4</property>
@ -356,7 +356,7 @@
</packing>
</child>
<child>
<object class="GtkEntry" id="detect-entry-y">
<object class="GtkEntry" id="detect-entry-posy">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="margin-left">4</property>
@ -405,12 +405,32 @@
</object>
<packing>
<property name="left-attach">5</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="detect-btnsetsize">
<property name="label" translatable="yes">Set Size</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="margin-left">8</property>
<property name="margin-right">8</property>
<property name="margin-start">8</property>
<property name="margin-end">8</property>
<property name="margin-top">4</property>
<property name="margin-bottom">4</property>
<signal name="activate" handler="cb_detect_btnsetsize" swapped="no"/>
<signal name="pressed" handler="cb_detect_btnsetsize" swapped="no"/>
</object>
<packing>
<property name="left-attach">6</property>
<property name="top-attach">1</property>
</packing>
</child>
<child>
<object class="GtkButton" id="detect-btnset">
<property name="label" translatable="yes">Set Object</property>
<object class="GtkButton" id="detect-btnsetpos">
<property name="label" translatable="yes">Set Pos</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
@ -420,14 +440,25 @@
<property name="margin-end">8</property>
<property name="margin-top">4</property>
<property name="margin-bottom">4</property>
<signal name="activate" handler="cb_detect_btnset" swapped="no"/>
<signal name="pressed" handler="cb_detect_btnset" swapped="no"/>
<signal name="activate" handler="cb_detect_btnsetpos" swapped="no"/>
<signal name="pressed" handler="cb_detect_btnsetpos" swapped="no"/>
</object>
<packing>
<property name="left-attach">5</property>
<property name="left-attach">6</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">_</property>
</object>
<packing>
<property name="left-attach">5</property>
<property name="top-attach">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>

@ -64,12 +64,20 @@ void videoframe_to_pixbuf(GdkPixbuf* dest, VideoFrame *src) {
}
#define S_X(_x_) (((_x_) * clientw / pixbufw))
#define S_Y(_y_) (((_y_) * clienth / pixbufh))
void cb_videoda_draw(GtkWidget *area, cairo_t *cr, int w, int h, gpointer data) {
int clientw, clienth, pixbufw, pixbufh;
float clientar, pixbufar;
GdkPixbuf *pixbuf = NULL;
GdkRGBA color;
GtkWidget *e_x = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "detect-entry-posx"));
GtkWidget *e_y = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "detect-entry-posy"));
GtkWidget *e_w = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "detect-entry-w"));
GtkWidget *e_h = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), "detect-entry-h"));
int x, y, w1, h1;
if (video_da == NULL) return;
clienth = gtk_widget_get_allocated_height(video_da);
@ -94,7 +102,49 @@ void cb_videoda_draw(GtkWidget *area, cairo_t *cr, int w, int h, gpointer data)
gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0);
cairo_paint(cr);
cairo_fill (cr);
g_object_unref (pixbuf);
//
// draw red cross
cairo_set_line_width(cr, 1.0);
color.blue = 0.0;
color.red = 1.0;
color.green = 0.0;
color.alpha = 1.0;
gdk_cairo_set_source_rgba(cr, &color);
x = atoi (gtk_entry_get_text(GTK_ENTRY(e_x)));
y = atoi (gtk_entry_get_text(GTK_ENTRY(e_y)));
w1 = atoi (gtk_entry_get_text(GTK_ENTRY(e_w)));
h1 = atoi (gtk_entry_get_text(GTK_ENTRY(e_h)));
cairo_move_to(cr, S_X(x), S_Y(y)-10);
cairo_line_to(cr, S_X(x), S_Y(y)+10);
cairo_move_to(cr, S_X(x)-10, S_Y(y));
cairo_line_to(cr, S_X(x)+10, S_Y(y));
cairo_stroke(cr);
//
// green width border
color.blue = 0.0;
color.red = 0.0;
color.green = 1.0;
color.alpha = 1.0;
gdk_cairo_set_source_rgba(cr, &color);
cairo_move_to(cr, S_X(x-w1/2), S_Y(y-h1/2)+10);
cairo_line_to(cr, S_X(x-w1/2), S_Y(y-h1/2));
cairo_line_to(cr, S_X(x+w1/2), S_Y(y-h1/2));
cairo_line_to(cr, S_X(x+w1/2), S_Y(y-h1/2)+10);
cairo_move_to(cr, S_X(x-w1/2), S_Y(y+h1/2)-10);
cairo_line_to(cr, S_X(x-w1/2), S_Y(y+h1/2));
cairo_line_to(cr, S_X(x+w1/2), S_Y(y+h1/2));
cairo_line_to(cr, S_X(x+w1/2), S_Y(y+h1/2)-10);
cairo_stroke(cr);
};

Loading…
Cancel
Save