From 10085a5d0129e0559074e8ef70508178413c325c Mon Sep 17 00:00:00 2001 From: Luis de Bethencourt Date: Wed, 14 Oct 2015 14:34:32 +0100 Subject: [PATCH] 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 --- ext/opencv/Makefile.am | 2 +- .../{gstmotioncells.c => gstmotioncells.cpp} | 45 +++++++++---------- ext/opencv/gstmotioncells.h | 22 ++------- ext/opencv/motioncells_wrapper.cpp | 3 ++ ext/opencv/motioncells_wrapper.h | 2 - 5 files changed, 29 insertions(+), 45 deletions(-) rename ext/opencv/{gstmotioncells.c => gstmotioncells.cpp} (96%) diff --git a/ext/opencv/Makefile.am b/ext/opencv/Makefile.am index 18184bc981..c1d6b1ad90 100644 --- a/ext/opencv/Makefile.am +++ b/ext/opencv/Makefile.am @@ -17,7 +17,7 @@ libgstopencv_la_SOURCES = gstopencv.cpp \ gstpyramidsegment.cpp \ gsttemplatematch.c \ gsttextoverlay.cpp \ - gstmotioncells.c \ + gstmotioncells.cpp \ gstskindetect.cpp \ gstretinex.cpp \ gstfacedetect.cpp \ diff --git a/ext/opencv/gstmotioncells.c b/ext/opencv/gstmotioncells.cpp similarity index 96% rename from ext/opencv/gstmotioncells.c rename to ext/opencv/gstmotioncells.cpp index 2de99abf77..c2dcab9cc3 100644 --- a/ext/opencv/gstmotioncells.c +++ b/ext/opencv/gstmotioncells.cpp @@ -2,7 +2,7 @@ * GStreamer MotioCells detect areas of motion * Copyright (C) 2011 Robert Jobbagy * Copyright (C) 2011 Nicola Murino - * + * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation @@ -67,7 +67,6 @@ #include #include "gstmotioncells.h" -#include "motioncells_wrapper.h" #include 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_param_spec_int ("gridx", "Number of Horizontal Grids", "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_param_spec_int ("gridy", "Number of Vertical Grids", "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_param_spec_double ("sensitivity", "Motion Sensitivity", "You can tunning the element motion sensitivity.", SENSITIVITY_MIN, 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_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_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_param_spec_int ("gap", "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. ", 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_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", 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_param_spec_int ("minimummotionframes", "MINIMUN MOTION FRAMES", "Define the minimum number of motion frames that trigger a motion event", MINIMUM_MOTION_FRAMES_MIN, MINIMUM_MOTION_FRAMES_MAX, 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_param_spec_boolean ("display", "Display", "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_param_spec_boolean ("postallmotion", "Post All Motion", "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_param_spec_boolean ("usealpha", "Use alpha", "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 /* FIXME: should not be a long property, make it either gint or gint64 * (is this property actually used or useful for anything?) */ g_object_class_install_property (gobject_class, PROP_DATE, g_param_spec_long ("date", "Motion Cell Date", "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 g_object_class_install_property (gobject_class, PROP_DATAFILE, g_param_spec_string ("datafile", "DataFile", "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_param_spec_string ("datafileextension", "DataFile Extension", "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_param_spec_string ("motionmaskcoords", "Motion Mask with Coordinates", "The upper left x, y and lower right x, y coordinates separated with \":\", " "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_param_spec_string ("motionmaskcellspos", "Motion Mask with Cells Position", "The line and column idx separated with \":\" what cells want we mask-out, " "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_param_spec_string ("cellscolor", "Color of Motion Cells", "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_param_spec_string ("motioncellsidx", "Motion Cells Of Interest(MOCI)", "The line and column idx separated with \":\", " "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_param_spec_boolean ("calculatemotion", "Calculate Motion", "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_param_spec_int ("motioncellthickness", "Motion Cell Thickness", "Motion Cell Border Thickness, if it's -1 then motion cell will be fill", 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, "motioncells", @@ -868,8 +867,8 @@ gst_motion_cells_chain (GstPad * pad, GstObject * parent, GstBuffer * buf) motioncells_count, i; int thickness, success, motioncellsidxcnt, numberOfCells, motioncellsnumber, cellsOfInterestNumber; - int mincellsOfInterestNumber, motiondetect, minimum_motion_frames, - postnomotion; + int mincellsOfInterestNumber, motiondetect; + uint minimum_motion_frames, postnomotion; char *datafile; bool display, changed_datafile, useAlpha; gint64 starttime; diff --git a/ext/opencv/gstmotioncells.h b/ext/opencv/gstmotioncells.h index 0a7daa0199..1d5505c420 100644 --- a/ext/opencv/gstmotioncells.h +++ b/ext/opencv/gstmotioncells.h @@ -47,6 +47,7 @@ #include #include +#include "motioncells_wrapper.h" G_BEGIN_DECLS /* #defines don't like whitespacey bits */ @@ -63,24 +64,6 @@ G_BEGIN_DECLS typedef struct _GstMotioncells GstMotioncells; 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 { GstElement element; @@ -99,7 +82,8 @@ struct _GstMotioncells cellscolor *motioncellscolor; motioncellidx *motioncellsidx, *motionmaskcellsidx; 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, last_nomotion_notified, prev_buff_timestamp, cur_buff_timestamp; gint64 diff_timestamp, starttime; diff --git a/ext/opencv/motioncells_wrapper.cpp b/ext/opencv/motioncells_wrapper.cpp index e9794cffb5..9bce838cd4 100644 --- a/ext/opencv/motioncells_wrapper.cpp +++ b/ext/opencv/motioncells_wrapper.cpp @@ -56,6 +56,9 @@ static int instanceCounter = 0; static bool element_id_was_max = false; +vector < instanceOfMC > motioncellsvector; +vector < int > motioncellsfreeids; + MotionCells *mc; char p_str[] = "idx failed"; diff --git a/ext/opencv/motioncells_wrapper.h b/ext/opencv/motioncells_wrapper.h index 1fe5dc3539..b6869a188f 100644 --- a/ext/opencv/motioncells_wrapper.h +++ b/ext/opencv/motioncells_wrapper.h @@ -54,8 +54,6 @@ struct instanceOfMC int id; MotionCells *mc; }; -vector < instanceOfMC > motioncellsvector; -vector < int >motioncellsfreeids; int searchIdx (int p_id); extern "C"