opencv: motioncells: Switch to C++

Switch gstmotioncells to C++ for consistency with other OpenCV elements,
and support of the new 2.4.11 API.

https://bugzilla.gnome.org/show_bug.cgi?id=754148
This commit is contained in:
Luis de Bethencourt 2015-10-14 14:34:32 +01:00
parent b02dd59b52
commit 10085a5d01
5 changed files with 29 additions and 45 deletions

View file

@ -17,7 +17,7 @@ libgstopencv_la_SOURCES = gstopencv.cpp \
gstpyramidsegment.cpp \ gstpyramidsegment.cpp \
gsttemplatematch.c \ gsttemplatematch.c \
gsttextoverlay.cpp \ gsttextoverlay.cpp \
gstmotioncells.c \ gstmotioncells.cpp \
gstskindetect.cpp \ gstskindetect.cpp \
gstretinex.cpp \ gstretinex.cpp \
gstfacedetect.cpp \ gstfacedetect.cpp \

View file

@ -2,7 +2,7 @@
* GStreamer MotioCells detect areas of motion * GStreamer MotioCells detect areas of motion
* Copyright (C) 2011 Robert Jobbagy <jobbagy.robert@gmail.com> * Copyright (C) 2011 Robert Jobbagy <jobbagy.robert@gmail.com>
* Copyright (C) 2011 Nicola Murino <nicola.murino@gmail.com> * Copyright (C) 2011 Nicola Murino <nicola.murino@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a * Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"), * copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation * to deal in the Software without restriction, including without limitation
@ -67,7 +67,6 @@
#include <glib.h> #include <glib.h>
#include "gstmotioncells.h" #include "gstmotioncells.h"
#include "motioncells_wrapper.h"
#include <gst/video/video.h> #include <gst/video/video.h>
GST_DEBUG_CATEGORY_STATIC (gst_motion_cells_debug); GST_DEBUG_CATEGORY_STATIC (gst_motion_cells_debug);
@ -214,95 +213,95 @@ gst_motion_cells_class_init (GstMotioncellsClass * klass)
g_object_class_install_property (gobject_class, PROP_GRID_X, g_object_class_install_property (gobject_class, PROP_GRID_X,
g_param_spec_int ("gridx", "Number of Horizontal Grids", g_param_spec_int ("gridx", "Number of Horizontal Grids",
"You can give number of horizontal grid cells.", GRID_MIN, GRID_MAX, "You can give number of horizontal grid cells.", GRID_MIN, GRID_MAX,
GRID_DEF, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); GRID_DEF, (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_GRID_Y, g_object_class_install_property (gobject_class, PROP_GRID_Y,
g_param_spec_int ("gridy", "Number of Vertical Grids", g_param_spec_int ("gridy", "Number of Vertical Grids",
"You can give number of vertical grid cells.", GRID_MIN, GRID_MAX, "You can give number of vertical grid cells.", GRID_MIN, GRID_MAX,
GRID_DEF, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); GRID_DEF, (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_SENSITIVITY, g_object_class_install_property (gobject_class, PROP_SENSITIVITY,
g_param_spec_double ("sensitivity", "Motion Sensitivity", g_param_spec_double ("sensitivity", "Motion Sensitivity",
"You can tunning the element motion sensitivity.", SENSITIVITY_MIN, "You can tunning the element motion sensitivity.", SENSITIVITY_MIN,
SENSITIVITY_MAX, SENSITIVITY_DEFAULT, SENSITIVITY_MAX, SENSITIVITY_DEFAULT,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_THRESHOLD, g_object_class_install_property (gobject_class, PROP_THRESHOLD,
g_param_spec_double ("threshold", "Lower bound of motion cells number", g_param_spec_double ("threshold", "Lower bound of motion cells number",
"Threshold value for motion, when motion cells number greater sum cells * threshold, we show motion.", "Threshold value for motion, when motion cells number greater sum cells * threshold, we show motion.",
THRESHOLD_MIN, THRESHOLD_MAX, THRESHOLD_DEFAULT, THRESHOLD_MIN, THRESHOLD_MAX, THRESHOLD_DEFAULT,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_GAP, g_object_class_install_property (gobject_class, PROP_GAP,
g_param_spec_int ("gap", g_param_spec_int ("gap",
"Gap is time in second, elapsed time from last motion timestamp. ", "Gap is time in second, elapsed time from last motion timestamp. ",
"If elapsed time minus form last motion timestamp is greater or equal than gap then we post motion finished bus message. ", "If elapsed time minus form last motion timestamp is greater or equal than gap then we post motion finished bus message. ",
GAP_MIN, GAP_MAX, GAP_DEF, GAP_MIN, GAP_MAX, GAP_DEF,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_POSTNOMOTION, g_object_class_install_property (gobject_class, PROP_POSTNOMOTION,
g_param_spec_int ("postnomotion", "POSTNOMOTION", g_param_spec_int ("postnomotion", "POSTNOMOTION",
"If non 0 post a no_motion event is posted on the bus if no motion is detected for N seconds", "If non 0 post a no_motion event is posted on the bus if no motion is detected for N seconds",
POST_NO_MOTION_MIN, POST_NO_MOTION_MAX, POST_NO_MOTION_DEF, POST_NO_MOTION_MIN, POST_NO_MOTION_MAX, POST_NO_MOTION_DEF,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_MINIMUNMOTIONFRAMES, g_object_class_install_property (gobject_class, PROP_MINIMUNMOTIONFRAMES,
g_param_spec_int ("minimummotionframes", "MINIMUN MOTION FRAMES", g_param_spec_int ("minimummotionframes", "MINIMUN MOTION FRAMES",
"Define the minimum number of motion frames that trigger a motion event", "Define the minimum number of motion frames that trigger a motion event",
MINIMUM_MOTION_FRAMES_MIN, MINIMUM_MOTION_FRAMES_MAX, MINIMUM_MOTION_FRAMES_MIN, MINIMUM_MOTION_FRAMES_MAX,
MINIMUM_MOTION_FRAMES_DEF, MINIMUM_MOTION_FRAMES_DEF,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_DISPLAY, g_object_class_install_property (gobject_class, PROP_DISPLAY,
g_param_spec_boolean ("display", "Display", g_param_spec_boolean ("display", "Display",
"Motion Cells visible or not on Current Frame", FALSE, "Motion Cells visible or not on Current Frame", FALSE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_POSTALLMOTION, g_object_class_install_property (gobject_class, PROP_POSTALLMOTION,
g_param_spec_boolean ("postallmotion", "Post All Motion", g_param_spec_boolean ("postallmotion", "Post All Motion",
"Element post bus msg for every motion frame or just motion start and motion stop", "Element post bus msg for every motion frame or just motion start and motion stop",
FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); FALSE, (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_USEALPHA, g_object_class_install_property (gobject_class, PROP_USEALPHA,
g_param_spec_boolean ("usealpha", "Use alpha", g_param_spec_boolean ("usealpha", "Use alpha",
"Use or not alpha blending on frames with motion cells", TRUE, "Use or not alpha blending on frames with motion cells", TRUE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
#if 0 #if 0
/* FIXME: should not be a long property, make it either gint or gint64 /* FIXME: should not be a long property, make it either gint or gint64
* (is this property actually used or useful for anything?) */ * (is this property actually used or useful for anything?) */
g_object_class_install_property (gobject_class, PROP_DATE, g_object_class_install_property (gobject_class, PROP_DATE,
g_param_spec_long ("date", "Motion Cell Date", g_param_spec_long ("date", "Motion Cell Date",
"Current Date in milliseconds", DATE_MIN, DATE_MAX, DATE_DEF, "Current Date in milliseconds", DATE_MIN, DATE_MAX, DATE_DEF,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
#endif #endif
g_object_class_install_property (gobject_class, PROP_DATAFILE, g_object_class_install_property (gobject_class, PROP_DATAFILE,
g_param_spec_string ("datafile", "DataFile", g_param_spec_string ("datafile", "DataFile",
"Location of motioncells data file (empty string means no saving)", "Location of motioncells data file (empty string means no saving)",
NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); NULL, (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_DATAFILE_EXT, g_object_class_install_property (gobject_class, PROP_DATAFILE_EXT,
g_param_spec_string ("datafileextension", "DataFile Extension", g_param_spec_string ("datafileextension", "DataFile Extension",
"Extension of datafile", DEF_DATAFILEEXT, "Extension of datafile", DEF_DATAFILEEXT,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_MOTIONMASKCOORD, g_object_class_install_property (gobject_class, PROP_MOTIONMASKCOORD,
g_param_spec_string ("motionmaskcoords", "Motion Mask with Coordinates", g_param_spec_string ("motionmaskcoords", "Motion Mask with Coordinates",
"The upper left x, y and lower right x, y coordinates separated with \":\", " "The upper left x, y and lower right x, y coordinates separated with \":\", "
"describe a region. Regions separated with \",\"", NULL, "describe a region. Regions separated with \",\"", NULL,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_MOTIONMASKCELLSPOS, g_object_class_install_property (gobject_class, PROP_MOTIONMASKCELLSPOS,
g_param_spec_string ("motionmaskcellspos", g_param_spec_string ("motionmaskcellspos",
"Motion Mask with Cells Position", "Motion Mask with Cells Position",
"The line and column idx separated with \":\" what cells want we mask-out, " "The line and column idx separated with \":\" what cells want we mask-out, "
"describe a cell. Cells separated with \",\"", NULL, "describe a cell. Cells separated with \",\"", NULL,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_CELLSCOLOR, g_object_class_install_property (gobject_class, PROP_CELLSCOLOR,
g_param_spec_string ("cellscolor", "Color of Motion Cells", g_param_spec_string ("cellscolor", "Color of Motion Cells",
"The color of motion cells separated with \",\"", "255,255,0", "The color of motion cells separated with \",\"", "255,255,0",
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_MOTIONCELLSIDX, g_object_class_install_property (gobject_class, PROP_MOTIONCELLSIDX,
g_param_spec_string ("motioncellsidx", "Motion Cells Of Interest(MOCI)", g_param_spec_string ("motioncellsidx", "Motion Cells Of Interest(MOCI)",
"The line and column idx separated with \":\", " "The line and column idx separated with \":\", "
"describe a cell. Cells separated with \",\"", NULL, "describe a cell. Cells separated with \",\"", NULL,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_CALCULATEMOTION, g_object_class_install_property (gobject_class, PROP_CALCULATEMOTION,
g_param_spec_boolean ("calculatemotion", "Calculate Motion", g_param_spec_boolean ("calculatemotion", "Calculate Motion",
"If needs calculate motion on frame you need this property setting true otherwise false", "If needs calculate motion on frame you need this property setting true otherwise false",
TRUE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); TRUE, (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_MOTIONCELLTHICKNESS, g_object_class_install_property (gobject_class, PROP_MOTIONCELLTHICKNESS,
g_param_spec_int ("motioncellthickness", "Motion Cell Thickness", g_param_spec_int ("motioncellthickness", "Motion Cell Thickness",
"Motion Cell Border Thickness, if it's -1 then motion cell will be fill", "Motion Cell Border Thickness, if it's -1 then motion cell will be fill",
THICKNESS_MIN, THICKNESS_MAX, THICKNESS_DEF, THICKNESS_MIN, THICKNESS_MAX, THICKNESS_DEF,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
gst_element_class_set_static_metadata (element_class, gst_element_class_set_static_metadata (element_class,
"motioncells", "motioncells",
@ -868,8 +867,8 @@ gst_motion_cells_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)
motioncells_count, i; motioncells_count, i;
int thickness, success, motioncellsidxcnt, numberOfCells, int thickness, success, motioncellsidxcnt, numberOfCells,
motioncellsnumber, cellsOfInterestNumber; motioncellsnumber, cellsOfInterestNumber;
int mincellsOfInterestNumber, motiondetect, minimum_motion_frames, int mincellsOfInterestNumber, motiondetect;
postnomotion; uint minimum_motion_frames, postnomotion;
char *datafile; char *datafile;
bool display, changed_datafile, useAlpha; bool display, changed_datafile, useAlpha;
gint64 starttime; gint64 starttime;

View file

@ -47,6 +47,7 @@
#include <gst/gst.h> #include <gst/gst.h>
#include <opencv2/core/core_c.h> #include <opencv2/core/core_c.h>
#include "motioncells_wrapper.h"
G_BEGIN_DECLS G_BEGIN_DECLS
/* #defines don't like whitespacey bits */ /* #defines don't like whitespacey bits */
@ -63,24 +64,6 @@ G_BEGIN_DECLS
typedef struct _GstMotioncells GstMotioncells; typedef struct _GstMotioncells GstMotioncells;
typedef struct _GstMotioncellsClass GstMotioncellsClass; typedef struct _GstMotioncellsClass GstMotioncellsClass;
typedef struct {
int upper_left_x;
int upper_left_y;
int lower_right_x;
int lower_right_y;
} motionmaskcoordrect;
typedef struct {
int R_channel_value;
int G_channel_value;
int B_channel_value;
} cellscolor;
typedef struct {
int lineidx;
int columnidx;
} motioncellidx;
struct _GstMotioncells struct _GstMotioncells
{ {
GstElement element; GstElement element;
@ -99,7 +82,8 @@ struct _GstMotioncells
cellscolor *motioncellscolor; cellscolor *motioncellscolor;
motioncellidx *motioncellsidx, *motionmaskcellsidx; motioncellidx *motioncellsidx, *motionmaskcellsidx;
int motionmaskcoord_count, motioncells_count, motionmaskcells_count; int motionmaskcoord_count, motioncells_count, motionmaskcells_count;
int gap, thickness, datafileidx, postnomotion, minimum_motion_frames; int thickness;
guint gap, datafileidx, postnomotion, minimum_motion_frames;
guint64 motion_begin_timestamp, last_motion_timestamp, motion_timestamp, guint64 motion_begin_timestamp, last_motion_timestamp, motion_timestamp,
last_nomotion_notified, prev_buff_timestamp, cur_buff_timestamp; last_nomotion_notified, prev_buff_timestamp, cur_buff_timestamp;
gint64 diff_timestamp, starttime; gint64 diff_timestamp, starttime;

View file

@ -56,6 +56,9 @@
static int instanceCounter = 0; static int instanceCounter = 0;
static bool element_id_was_max = false; static bool element_id_was_max = false;
vector < instanceOfMC > motioncellsvector;
vector < int > motioncellsfreeids;
MotionCells *mc; MotionCells *mc;
char p_str[] = "idx failed"; char p_str[] = "idx failed";

View file

@ -54,8 +54,6 @@ struct instanceOfMC
int id; int id;
MotionCells *mc; MotionCells *mc;
}; };
vector < instanceOfMC > motioncellsvector;
vector < int >motioncellsfreeids;
int searchIdx (int p_id); int searchIdx (int p_id);
extern "C" extern "C"