diff options
author | Luis de Bethencourt <luisbg@osg.samsung.com> | 2016-03-31 16:08:12 +0100 |
---|---|---|
committer | Luis de Bethencourt <luisbg@osg.samsung.com> | 2016-03-31 16:12:04 +0100 |
commit | 9d7b525f1956c33b6a8c08100ce94ea6137b7d14 (patch) | |
tree | c0a4ecd6c37e1d5991ed5d9e25a79faed1995532 /ext/opencv | |
parent | 8b310665c50e9c3dc78a3b1381bec84a899c78d4 (diff) | |
download | gstreamer-plugins-bad-9d7b525f1956c33b6a8c08100ce94ea6137b7d14.tar.gz |
motioncells: fully construct MotionCells
Some members of MotionCells were not being initialized in the constructor.
Protect from potential garbage memory usage by fully initializing it.
Moving m_frameSize out of the class because it is only used in
performDetectionMotionCells().
CID 1197704
Diffstat (limited to 'ext/opencv')
-rw-r--r-- | ext/opencv/MotionCells.cpp | 36 | ||||
-rw-r--r-- | ext/opencv/MotionCells.h | 1 |
2 files changed, 22 insertions, 15 deletions
diff --git a/ext/opencv/MotionCells.cpp b/ext/opencv/MotionCells.cpp index 9a161760d..53d33718f 100644 --- a/ext/opencv/MotionCells.cpp +++ b/ext/opencv/MotionCells.cpp @@ -79,6 +79,15 @@ MotionCells::MotionCells () m_cellwidth = 0; m_cellheight = 0; m_sensitivity = 0; + + memset (&m_header, 0, sizeof (MotionCellHeader)); + m_header.headersize = GINT32_TO_BE (MC_HEADER); + m_header.type = GINT32_TO_BE (MC_TYPE); + m_header.version = GINT32_TO_BE (MC_VERSION); + m_header.itemsize = 0; + m_header.gridx = 0; + m_header.gridy = 0; + m_header.starttime = 0; } MotionCells::~MotionCells () @@ -116,6 +125,8 @@ MotionCells::performDetectionMotionCells (IplImage * p_frame, int sumframecnt = 0; int ret = 0; + CvSize frameSize; + p_framerate >= 1 ? p_framerate <= 5 ? sumframecnt = 1 : p_framerate <= 10 ? sumframecnt = 2 : p_framerate <= 15 ? sumframecnt = 3 @@ -135,21 +146,21 @@ MotionCells::performDetectionMotionCells (IplImage * p_frame, return ret; } - m_frameSize = cvGetSize (p_frame); - m_frameSize.width /= 2; - m_frameSize.height /= 2; - setMotionCells (m_frameSize.width, m_frameSize.height); + frameSize = cvGetSize (p_frame); + frameSize.width /= 2; + frameSize.height /= 2; + setMotionCells (frameSize.width, frameSize.height); m_sensitivity = 1 - p_sensitivity; m_isVisible = p_isVisible; m_pcurFrame = cvCloneImage (p_frame); - IplImage *m_pcurgreyImage = cvCreateImage (m_frameSize, IPL_DEPTH_8U, 1); - IplImage *m_pprevgreyImage = cvCreateImage (m_frameSize, IPL_DEPTH_8U, 1); - IplImage *m_pgreyImage = cvCreateImage (m_frameSize, IPL_DEPTH_8U, 1); + IplImage *m_pcurgreyImage = cvCreateImage (frameSize, IPL_DEPTH_8U, 1); + IplImage *m_pprevgreyImage = cvCreateImage (frameSize, IPL_DEPTH_8U, 1); + IplImage *m_pgreyImage = cvCreateImage (frameSize, IPL_DEPTH_8U, 1); IplImage *m_pcurDown = - cvCreateImage (m_frameSize, m_pcurFrame->depth, m_pcurFrame->nChannels); - IplImage *m_pprevDown = cvCreateImage (m_frameSize, m_pprevFrame->depth, + cvCreateImage (frameSize, m_pcurFrame->depth, m_pcurFrame->nChannels); + IplImage *m_pprevDown = cvCreateImage (frameSize, m_pprevFrame->depth, m_pprevFrame->nChannels); - m_pbwImage = cvCreateImage (m_frameSize, IPL_DEPTH_8U, 1); + m_pbwImage = cvCreateImage (frameSize, IPL_DEPTH_8U, 1); cvPyrDown (m_pprevFrame, m_pprevDown); cvCvtColor (m_pprevDown, m_pprevgreyImage, CV_RGB2GRAY); cvPyrDown (m_pcurFrame, m_pcurDown); @@ -333,10 +344,7 @@ MotionCells::initDataFile (char *p_datafile, gint64 starttime) //p_date is incr } } else mc_savefile = NULL; - memset (&m_header, 0, sizeof (MotionCellHeader)); - m_header.headersize = GINT32_TO_BE (MC_HEADER); - m_header.type = GINT32_TO_BE (MC_TYPE); - m_header.version = GINT32_TO_BE (MC_VERSION); + //it needs these bytes m_header.itemsize = GINT32_TO_BE ((int) ceil (ceil (m_gridx * m_gridy / 8.0) / 4.0) * 4 + diff --git a/ext/opencv/MotionCells.h b/ext/opencv/MotionCells.h index 97137bbd5..c858d8739 100644 --- a/ext/opencv/MotionCells.h +++ b/ext/opencv/MotionCells.h @@ -242,7 +242,6 @@ private: IplImage *m_pcurFrame, *m_pprevFrame, *m_pdifferenceImage, *m_pbwImage,*transparencyimg; - CvSize m_frameSize; bool m_isVisible, m_changed_datafile, m_useAlpha, m_saveInDatafile; Cell **m_pCells; vector < MotionCellsIdx > m_MotionCells; |