[openrtm-commit:01128] r98 - in branches/newCMakeForVC2010/ImageProcessing/opencv/components/BackGroundSubtractionSimple: include/BackGroundSubtractionSimple src
openrtm @ openrtm.org
openrtm @ openrtm.org
2013年 9月 26日 (木) 13:39:49 JST
Author: kawauchi
Date: 2013-09-26 13:39:49 +0900 (Thu, 26 Sep 2013)
New Revision: 98
Modified:
branches/newCMakeForVC2010/ImageProcessing/opencv/components/BackGroundSubtractionSimple/include/BackGroundSubtractionSimple/BackGroundSubtractionSimple.h
branches/newCMakeForVC2010/ImageProcessing/opencv/components/BackGroundSubtractionSimple/src/BackGroundSubtractionSimple.cpp
Log:
BackGroundSubtractionSimple component has been changed to use member function from a static function usage. refs #2704
Modified: branches/newCMakeForVC2010/ImageProcessing/opencv/components/BackGroundSubtractionSimple/include/BackGroundSubtractionSimple/BackGroundSubtractionSimple.h
===================================================================
--- branches/newCMakeForVC2010/ImageProcessing/opencv/components/BackGroundSubtractionSimple/include/BackGroundSubtractionSimple/BackGroundSubtractionSimple.h 2013-09-09 06:21:46 UTC (rev 97)
+++ branches/newCMakeForVC2010/ImageProcessing/opencv/components/BackGroundSubtractionSimple/include/BackGroundSubtractionSimple/BackGroundSubtractionSimple.h 2013-09-26 04:39:49 UTC (rev 98)
@@ -23,19 +23,17 @@
#include <cxcore.h>
#include <highgui.h>
-#define THRESHOLD 20 // ·ªðßéÛÌèl
-#define THRESHOLD_MAX_VALUE 255 // 2l»ÌÛÉgp·éÅål
-#define SCALE ( 1.0 / 255.0 ) // L*a*b*ÉÏ··é½ßÉKvÈXP[t@N^
+#define THRESHOLD_MAX_VALUE 255 // 2å¤åã®éã«ä½¿ç¨ããæ大å¤
+#define SCALE ( 1.0 / 255.0 ) // L*a*b*ã«å¤æããããã«å¿
è¦ãªã¹ã±ã¼ã«ãã¡ã¯ã¿
-#define CAPTURE_OFF 0 // æÌLv`ð~·étOl
-#define CAPTURE_ON 1 // æÌLv`ðJn·étOl
-#define COLOR_DIFFERENCE 0 // RGBe¬ªÉ¨¯é·ªZoÌtOl
-#define LAB_DIFFERENCE 1 // L*a*b*\Fnɨ¯é·ªZoÌtOl
-#define GRAY_DIFFERENCE 2 // O[XP[ɨ¯é·ªZoÌtOl
-#define NOISE_KEEP 0 // mCYðµÈ¢tOl
-#define NOISE_MORPHOLOGY 1 // tHW[ZÉæémCYÌtOl
-#define NOISE_MEDIAN 2 // fBAtB^ÉæémCYÌtOl
+#define COLOR_DIFFERENCE 0 // RGBåæåã«ãããå·®åç®åºã®ãã©ã°å¤
+#define LAB_DIFFERENCE 1 // L*a*b*表è²ç³»ã«ãããå·®åç®åºã®ãã©ã°å¤
+#define GRAY_DIFFERENCE 2 // ã°ã¬ã¼ã¹ã±ã¼ã«ã«ãããå·®åç®åºã®ãã©ã°å¤
+#define NOISE_KEEP 0 // ãã¤ãºãé¤å»ããªããã©ã°å¤
+#define NOISE_MORPHOLOGY 1 // ã¢ã«ãã©ãã¸ã¼æ¼ç®ã«ãããã¤ãºé¤å»ã®ãã©ã°å¤
+#define NOISE_MEDIAN 2 // ã¡ãã£ã¢ã³ãã£ã«ã¿ã«ãããã¤ãºé¤å»ã®ãã©ã°å¤
+
// Service implementation headers
// <rtc-template block="service_impl_h">
@@ -243,21 +241,27 @@
/*!
*
* - Name: cont_mode
- * - DefaultValue: a
+ * - DefaultValue: b
*/
char m_cont_mode;
- /*!
+ /*!
*
- * - Name: img_height
- * - DefaultValue: 240
+ * - Name: diff_mode
+ * - DefaultValue: b
*/
- int m_img_height;
+ char m_diff_mode;
+ /*!
+ *
+ * - Name: noise_mode
+ * - DefaultValue: b
+ */
+ char m_noise_mode;
/*!
*
- * - Name: img_width
- * - DefaultValue: 320
+ * - Name: nThresholdLv
+ * - DefaultValue: 20
*/
- int m_img_width;
+ int m_nThresholdLv;
// </rtc-template>
@@ -315,7 +319,21 @@
// <rtc-template block="private_operation">
// </rtc-template>
+ void colorDifference( void );
+ void labDifference( void );
+ void grayScaleDifference( void );
+ IplImage *m_originalImage;
+ IplImage *m_currentImage;
+ IplImage *m_backgroundImage;
+ IplImage *m_resultImage;
+ IplImage *m_outputImage;
+
+ int m_differenceMode; // å·®åã®è¨ç®ã¢ã¼ã
+ int m_noiseMode; // ãã¤ãºãé¤å»ããã¢ã¼ã
+ int m_temp_w;
+ int m_temp_h;
+
};
Modified: branches/newCMakeForVC2010/ImageProcessing/opencv/components/BackGroundSubtractionSimple/src/BackGroundSubtractionSimple.cpp
===================================================================
--- branches/newCMakeForVC2010/ImageProcessing/opencv/components/BackGroundSubtractionSimple/src/BackGroundSubtractionSimple.cpp 2013-09-09 06:21:46 UTC (rev 97)
+++ branches/newCMakeForVC2010/ImageProcessing/opencv/components/BackGroundSubtractionSimple/src/BackGroundSubtractionSimple.cpp 2013-09-26 04:39:49 UTC (rev 98)
@@ -26,41 +26,27 @@
"lang_type", "compile",
// Configuration variables
"conf.default.control_mode", "b",
- "conf.default.image_height", "240",
- "conf.default.image_width", "320",
+ "conf.default.diff_mode", "0",
+ "conf.default.noise_mode", "0",
+ "conf.default.threshold_level", "20",
// Widget
"conf.__widget__.control_mode", "radio",
- "conf.__widget__.image_height", "text",
- "conf.__widget__.image_width", "text",
+ "conf.__widget__.diff_mode", "radio",
+ "conf.__widget__.noise_mode", "radio",
+ "conf.__widget__.threshold_level", "slider.1",
// Constraints
- "conf.__constraints__.control_mode", "(b,m,n)",
+ "conf.__constraints__.control_mode", "(b,M)",
+ "conf.__constraints__.diff_mode", "(0,1,2)",
+ "conf.__constraints__.noise_mode", "(0,1,2)",
+ "conf.__constraints__.threshold_level", "0<=x<=255",
""
};
// </rtc-template>
-//char windowNameCurrent[] = "Current"; // »ÝÌæð\¦·éEBhE̼O
-//char windowNameResult[] = "Result"; // wi·ªÊð\¦·éEBhE̼O
-//char windowNameBackground[] = "Background"; // wiæð\¦·éEBhE̼O
-
-int captureOn = CAPTURE_ON; // wi·ªðs¤æðXV·é©Ç¤©
-int differenceMode = COLOR_DIFFERENCE; // ·ªÌvZ[h
-int noiseMode = NOISE_KEEP; // mCYð·é[h
-
-int g_temp_w = 0;
-int g_temp_h = 0;
-
-
-IplImage *originalImage = NULL;
-IplImage *currentImage = NULL;
-IplImage *backgroundImage = NULL;
-IplImage *resultImage = NULL;
-IplImage *outputImage = NULL;
-
-//char *differenceMethod[3] = {
std::string differenceMethod[3] = {
- "Evaluate each component of RGB", //RGB̬ª²ÆÉ]¿
- "Evaluate the distance in CIE L * a * b *", //CIE L*a*b* Å£ð]¿
- "Evaluated by gray scale" //O[XP[Å]¿
+ "RGB", //RGBã®æåãã¨ã«è©ä¾¡
+ "CIE L*a*b*", //CIE L*a*b* ã§è·é¢ãè©ä¾¡
+ "gray scale" //ã°ã¬ã¼ã¹ã±ã¼ã«ã§è©ä¾¡
};
std::string noiseMethod[3] = {
@@ -69,110 +55,6 @@
"Median filter"
};
-void colorDifference( IplImage *currentImage, IplImage *backgroundImage, IplImage *resultImage ){
-
- // æ𶬷é
- IplImage *differenceImage = cvCreateImage(cvSize(currentImage->width, currentImage->height), IPL_DEPTH_8U, 3); // ỾpIplImage
- IplImage *differenceRImage = cvCreateImage(cvSize(currentImage->width, currentImage->height), IPL_DEPTH_8U, 1); // RlÌ·ªpIplImage
- IplImage *differenceGImage = cvCreateImage(cvSize(currentImage->width, currentImage->height), IPL_DEPTH_8U, 1); // GlÌ·ªpIplImage
- IplImage *differenceBImage = cvCreateImage(cvSize(currentImage->width, currentImage->height), IPL_DEPTH_8U, 1); // BlÌ·ªpIplImage
-
- // »ÝÌwiÆÌ·ÌâÎl𬪲ÆÉæé
- cvAbsDiff( currentImage, backgroundImage, differenceImage );
-
- // èlðs¤
- cvThreshold( differenceImage, differenceImage, THRESHOLD, THRESHOLD_MAX_VALUE, CV_THRESH_BINARY );
-
- // ¬ª²ÆÌæɪ·é
- cvSplit( differenceImage, differenceBImage, differenceGImage, differenceRImage, NULL );
-
- // ORŬ·é
- cvOr( differenceRImage, differenceGImage, resultImage );
- cvOr( differenceBImage, resultImage, resultImage );
-
- // ððú·é
- cvReleaseImage( &differenceImage );
- cvReleaseImage( &differenceRImage );
- cvReleaseImage( &differenceGImage );
- cvReleaseImage( &differenceBImage );
-
-}
-
-//
-// L*a*b*Å£ð]¿·é
-//
-// ø:
-// currentImage : »ÝÌæpIplImage
-// backgroundImage : wiæpIplImage
-// resultImage : ÊæpIplImage
-//
-void labDifference( IplImage *currentImage, IplImage *backgroundImage, IplImage *resultImage ){
-
- // æ𶬷é
- IplImage *currentLabImage = cvCreateImage( cvSize(currentImage->width, currentImage->height),IPL_DEPTH_32F, 3 ); // »ÝÌæðL*a*b*ÉÏ·µ½æpIplImage
- IplImage *backgroundLabImage = cvCreateImage( cvSize(currentImage->width, currentImage->height), IPL_DEPTH_32F, 3 ); // wiðL*a*b*ÉÏ·µ½æpIplImage
- IplImage *differenceLabImage = cvCreateImage( cvSize(currentImage->width, currentImage->height), IPL_DEPTH_32F, 3 ); // ỾpIplImage
- IplImage *differenceLImage = cvCreateImage( cvSize(currentImage->width, currentImage->height), IPL_DEPTH_32F, 1 ); // L*lÌ·ªpIplImage
- IplImage *differenceAImage = cvCreateImage( cvSize(currentImage->width, currentImage->height), IPL_DEPTH_32F, 1 ); // a*lÌ·ªpIplImage
- IplImage *differenceBImage = cvCreateImage( cvSize(currentImage->width, currentImage->height), IPL_DEPTH_32F, 1 ); // b*lÌ·ªpIplImage
- IplImage *sqrDifferenceImage = cvCreateImage( cvSize(currentImage->width, currentImage->height), IPL_DEPTH_32F, 1 ); // £ZopIplImage
-
- // »ÝÌæÆwið¤É CIE L*a*b* ÉÏ·
- cvConvertScale( currentImage, currentLabImage, SCALE );
- cvConvertScale( backgroundImage, backgroundLabImage, SCALE );
- cvCvtColor( currentLabImage, currentLabImage, CV_BGR2Lab );
- cvCvtColor( backgroundLabImage, backgroundLabImage, CV_BGR2Lab );
-
- // £ÌñæðvZ·é
- cvSub( currentLabImage, backgroundLabImage, differenceLabImage );
- cvPow( differenceLabImage, differenceLabImage, 2 );
-
- // ¬ª²ÆÌæɪ·é
- cvSplit( differenceLabImage, differenceLImage, differenceAImage, differenceBImage, NULL );
-
- cvCopy( differenceLImage, sqrDifferenceImage );
- cvAdd( differenceAImage, sqrDifferenceImage, sqrDifferenceImage );
- cvAdd( differenceBImage, sqrDifferenceImage, sqrDifferenceImage );
-
- // èlðs¤
- cvThreshold( sqrDifferenceImage, resultImage, THRESHOLD * THRESHOLD, THRESHOLD_MAX_VALUE, CV_THRESH_BINARY );
-
- // ððú·é
- cvReleaseImage( ¤tLabImage );
- cvReleaseImage( &backgroundLabImage );
- cvReleaseImage( &differenceLabImage );
- cvReleaseImage( &differenceLImage );
- cvReleaseImage( &differenceAImage );
- cvReleaseImage( &differenceBImage );
- cvReleaseImage( &sqrDifferenceImage );
-}
-
-//
-// O[XP[Å]¿·é
-//
-// ø:
-// currentImage : »ÝÌæpIplImage
-// backgroundImage : wiæpIplImage
-// resultImage : ÊæpIplImage
-//
-void grayScaleDifference( IplImage *currentImage, IplImage *backgroundImage, IplImage *resultImage ){
-
- // æ𶬷é
- IplImage *differenceImage = cvCreateImage( cvSize(currentImage->width, currentImage->height), IPL_DEPTH_8U, 3 ); // ỾpIplImage
-
- // »ÝÌwiÆÌ·ÌâÎl𬪲ÆÉæé
- cvAbsDiff( currentImage, backgroundImage, differenceImage );
-
- // BGR©çO[XP[ÉÏ··é
- cvCvtColor( differenceImage, resultImage, CV_BGR2GRAY );
-
- // O[XP[©ç2lÉÏ··é
- cvThreshold( resultImage, resultImage, THRESHOLD, THRESHOLD_MAX_VALUE, CV_THRESH_BINARY );
-
- // ððú·é
- cvReleaseImage( &differenceImage );
-}
-
/*!
* @brief constructor
* @param manager Maneger Object
@@ -222,10 +104,17 @@
// <rtc-template block="bind_config">
// Bind variables and configuration variable
- bindParameter("control_mode", m_cont_mode, "a");
- bindParameter("image_height", m_img_height, "240");
- bindParameter("image_width", m_img_width, "320");
+ bindParameter("control_mode", m_cont_mode, "b");
+ bindParameter("diff_mode", m_diff_mode, "0");
+ bindParameter("noise_mode", m_noise_mode, "0");
+ bindParameter("threshold_level", m_nThresholdLv, "20");
// </rtc-template>
+
+ m_originalImage = NULL;
+ m_currentImage = NULL;
+ m_backgroundImage = NULL;
+ m_resultImage = NULL;
+ m_outputImage = NULL;
return RTC::RTC_OK;
}
@@ -254,51 +143,40 @@
RTC::ReturnCode_t BackGroundSubtractionSimple::onActivated(RTC::UniqueId ec_id)
{
- captureOn = CAPTURE_ON; // wi·ªðs¤æðXV·é©Ç¤©
- differenceMode = COLOR_DIFFERENCE; // ·ªÌvZ[h
- noiseMode = NOISE_KEEP; // mCYð·é[h
+ m_differenceMode = COLOR_DIFFERENCE; // å·®åã®è¨ç®ã¢ã¼ã
+ m_noiseMode = NOISE_KEEP; // ãã¤ãºãé¤å»ããã¢ã¼ã
- g_temp_w = 0;
- g_temp_h = 0;
+ m_temp_w = 0;
+ m_temp_h = 0;
- if(originalImage != NULL){
- cvReleaseImage(&originalImage);
- }
- if(currentImage != NULL){
- cvReleaseImage(¤tImage);
- }
- if(resultImage != NULL){
- cvReleaseImage(&resultImage);
- }
- if(outputImage != NULL){
- cvReleaseImage(&outputImage);
- }
- if(backgroundImage != NULL){
- cvReleaseImage(&backgroundImage);
- }
-
return RTC::RTC_OK;
}
RTC::ReturnCode_t BackGroundSubtractionSimple::onDeactivated(RTC::UniqueId ec_id)
{
- if(originalImage != NULL){
- cvReleaseImage(&originalImage);
+ if(m_originalImage != NULL){
+ cvReleaseImage(&m_originalImage);
}
- if(currentImage != NULL){
- cvReleaseImage(¤tImage);
+ if(m_currentImage != NULL){
+ cvReleaseImage(&m_currentImage);
}
- if(resultImage != NULL){
- cvReleaseImage(&resultImage);
+ if(m_resultImage != NULL){
+ cvReleaseImage(&m_resultImage);
}
- if(outputImage != NULL){
- cvReleaseImage(&outputImage);
+ if(m_outputImage != NULL){
+ cvReleaseImage(&m_outputImage);
}
- if(backgroundImage != NULL){
- cvReleaseImage(&backgroundImage);
+ if(m_backgroundImage != NULL){
+ cvReleaseImage(&m_backgroundImage);
}
+ m_originalImage = NULL;
+ m_currentImage = NULL;
+ m_backgroundImage = NULL;
+ m_resultImage = NULL;
+ m_outputImage = NULL;
+
return RTC::RTC_OK;
}
@@ -308,152 +186,126 @@
if(m_img_origIn.isNew()) {
- //C[WRead
+ //ã¤ã¡ã¼ã¸Read
m_img_origIn.read();
- if(originalImage == NULL){
- originalImage = cvCreateImage(cvSize(m_img_orig.width, m_img_orig.height), IPL_DEPTH_8U, 3);
+ if(m_originalImage == NULL){
+ m_originalImage = cvCreateImage(cvSize(m_img_orig.width, m_img_orig.height), IPL_DEPTH_8U, 3);
}
- if(currentImage == NULL){
- currentImage = cvCreateImage(cvSize(m_img_orig.width, m_img_orig.height), IPL_DEPTH_8U, 3);
+ if(m_currentImage == NULL){
+ m_currentImage = cvCreateImage(cvSize(m_img_orig.width, m_img_orig.height), IPL_DEPTH_8U, 3);
}
- if(m_img_orig.width != g_temp_w || m_img_orig.height != g_temp_h){
+ if(m_img_orig.width != m_temp_w || m_img_orig.height != m_temp_h){
- if(backgroundImage != NULL){
- cvReleaseImage(&backgroundImage);
+ if(m_backgroundImage != NULL){
+ cvReleaseImage(&m_backgroundImage);
}
- backgroundImage = cvCreateImage(cvSize(m_img_orig.width, m_img_orig.height), IPL_DEPTH_8U, 3);
+ m_backgroundImage = cvCreateImage(cvSize(m_img_orig.width, m_img_orig.height), IPL_DEPTH_8U, 3);
}
- if(resultImage == NULL){
- resultImage = cvCreateImage(cvSize(m_img_orig.width, m_img_orig.height), IPL_DEPTH_8U, 1);
+ if(m_resultImage == NULL){
+ m_resultImage = cvCreateImage(cvSize(m_img_orig.width, m_img_orig.height), IPL_DEPTH_8U, 1);
}
- if(outputImage == NULL){
- outputImage = cvCreateImage(cvSize(m_img_orig.width, m_img_orig.height), IPL_DEPTH_8U, 3);
+ if(m_outputImage == NULL){
+ m_outputImage = cvCreateImage(cvSize(m_img_orig.width, m_img_orig.height), IPL_DEPTH_8U, 3);
}
- // æð1Lv`µwiƵÄÛ¶·é
- //backgroundImage = cvCloneImage( originalImage );
-
- // »ÝÌæƵÄà1mÛ·é
- //currentImage = cvCloneImage( originalImage );
-
- //InPortÌfÌæ¾
- memcpy(originalImage->imageData,(void *)&(m_img_orig.pixels[0]),m_img_orig.pixels.length());
-
- if( captureOn != 0){
- if( currentImage != NULL){
- cvReleaseImage( ¤tImage );
- }
- currentImage = cvCloneImage( originalImage );
- }
+ //InPortã®æ åã®åå¾
+ memcpy(m_originalImage->imageData,(void *)&(m_img_orig.pixels[0]),m_img_orig.pixels.length());
+ m_currentImage = cvCloneImage( m_originalImage );
- // ·ÌvZû@ÌØèÖ¦
- if( differenceMode == COLOR_DIFFERENCE ){
- // ¬ª²ÆÉ]¿ð·é
- colorDifference( currentImage, backgroundImage, resultImage );
- } else if( differenceMode == LAB_DIFFERENCE ){
- // L*a*b*Å£ð]¿·é
- labDifference( currentImage, backgroundImage, resultImage );
- } else if( differenceMode == GRAY_DIFFERENCE ){
- // O[XP[Å]¿ð·é
- grayScaleDifference( currentImage, backgroundImage, resultImage );
+ // å·®ã®è¨ç®æ¹æ³ã®åãæ¿ã
+ if( m_differenceMode == COLOR_DIFFERENCE ){
+ // æåãã¨ã«è©ä¾¡ããã
+ colorDifference();
+ } else if( m_differenceMode == LAB_DIFFERENCE ){
+ // L*a*b*ã§è·é¢ãè©ä¾¡ãã
+ labDifference();
+ } else if( m_differenceMode == GRAY_DIFFERENCE ){
+ // ã°ã¬ã¼ã¹ã±ã¼ã«ã§è©ä¾¡ããã
+ grayScaleDifference();
}
- // mCY
- if( noiseMode == NOISE_MORPHOLOGY ){
- cvErode( resultImage, resultImage );
- cvDilate( resultImage, resultImage );
- }else if ( noiseMode == NOISE_MEDIAN ){
- cvSmooth( resultImage, resultImage, CV_MEDIAN );
+ // ãã¤ãºé¤å»
+ if( m_noiseMode == NOISE_MORPHOLOGY ){
+ cvErode( m_resultImage, m_resultImage );
+ cvDilate( m_resultImage, m_resultImage );
+ }else if ( m_noiseMode == NOISE_MEDIAN ){
+ cvSmooth( m_resultImage, m_resultImage, CV_MEDIAN );
}
- if( resultImage->origin == 0 ){
- //@¶ãª´_Ìê
- //cvFlip( resultImage, resultImage, 0 );
- }
-
- cvMerge( resultImage, resultImage, resultImage, NULL, outputImage );
+ cvMerge( m_resultImage, m_resultImage, m_resultImage, NULL, m_outputImage );
- // æf[^ÌTCYæ¾
- double len1 = (currentImage->nChannels * currentImage->width * currentImage->height);
- double len2 = (outputImage->nChannels * outputImage->width * outputImage->height);
- double len3 = (backgroundImage->nChannels * backgroundImage->width * backgroundImage->height);
+ // ç»åãã¼ã¿ã®ãµã¤ãºåå¾
+ double len1 = (m_currentImage->nChannels * m_currentImage->width * m_currentImage->height);
+ double len2 = (m_outputImage->nChannels * m_outputImage->width * m_outputImage->height);
+ double len3 = (m_backgroundImage->nChannels * m_backgroundImage->width * m_backgroundImage->height);
m_img_curr.pixels.length(len1);
m_img_resu.pixels.length(len2);
m_img_back.pixels.length(len3);
- // YÌC[WðMemCopy·é
- memcpy((void *)&(m_img_curr.pixels[0]), currentImage->imageData, len1);
- memcpy((void *)&(m_img_resu.pixels[0]), outputImage->imageData, len2);
- memcpy((void *)&(m_img_back.pixels[0]), backgroundImage->imageData, len3);
+ // 該å½ã®ã¤ã¡ã¼ã¸ãMemCopyãã
+ memcpy((void *)&(m_img_curr.pixels[0]), m_currentImage->imageData, len1);
+ memcpy((void *)&(m_img_resu.pixels[0]), m_outputImage->imageData, len2);
+ memcpy((void *)&(m_img_back.pixels[0]), m_backgroundImage->imageData, len3);
- m_img_curr.width = originalImage->width;
- m_img_curr.height = originalImage->height;
+ m_img_curr.width = m_originalImage->width;
+ m_img_curr.height = m_originalImage->height;
- m_img_resu.width = originalImage->width;
- m_img_resu.height = originalImage->height;
+ m_img_resu.width = m_originalImage->width;
+ m_img_resu.height = m_originalImage->height;
- m_img_back.width = originalImage->width;
- m_img_back.height = originalImage->height;
+ m_img_back.width = m_originalImage->width;
+ m_img_back.height = m_originalImage->height;
m_img_currOut.write();
m_img_resuOut.write();
m_img_backOut.write();
-
- // æð\¦·é
- //cvShowImage( windowNameCurrent, currentImage );
- //cvShowImage( windowNameResult, resultImage );
- //cvShowImage( windowNameBackground, backgroundImage );
-
- //KeyüÍRead
+
+ //Keyå
¥åRead
if(m_keyIn.isNew()){
m_keyIn.read();
-
- if(m_cont_mode == 'b'){
- if(backgroundImage != NULL) {
- cvReleaseImage(&backgroundImage);
+
+ if(m_cont_mode == 'b')
+ {
+ //èæ¯ç»åæ´æ°
+ if(m_backgroundImage != NULL) {
+ cvReleaseImage(&m_backgroundImage);
}
- backgroundImage = cvCloneImage(originalImage);
- //backgroundImage = NULL;
- printf( "Background image update\n" ); //wiæXV
+ m_backgroundImage = cvCloneImage(m_originalImage);
+ printf( "Background image update( %s : %s )\n",
+ differenceMethod[m_differenceMode].c_str(), noiseMethod[m_noiseMode].c_str() );
- }else if(m_cont_mode == 'm'){
- differenceMode = differenceMode + 1;
- if( differenceMode > GRAY_DIFFERENCE ){
- differenceMode = COLOR_DIFFERENCE;
- }
- printf( "Evaluation method of difference: %s\n", differenceMethod[differenceMode].c_str() ); //·Ì]¿û@
- }else if( m_cont_mode == 'n' ){
- // 'n'L[ª³ê½çmCYû@ðÏX·é
- noiseMode = noiseMode + 1;
- if( noiseMode > NOISE_MEDIAN ){
- noiseMode = NOISE_KEEP;
- }
- printf( "Noise removal method: %s\n", noiseMethod[noiseMode].c_str() ); //mCYû@
+ }else if(m_cont_mode == 'M')
+ {
+ //å·®ã®è©ä¾¡æ¹æ³ã»ãã¤ãºé¤å»æ¹æ³å¤æ´
+ m_differenceMode = (int)(m_diff_mode - '0');
+ m_noiseMode = (int)(m_noise_mode - '0');
+ printf( "Change method: (diff : noise) = (%s : %s)\n",
+ differenceMethod[m_differenceMode].c_str(), noiseMethod[m_noiseMode].c_str() );
}
}
- if(originalImage != NULL){
- cvReleaseImage(&originalImage);
+ if(m_originalImage != NULL){
+ cvReleaseImage(&m_originalImage);
}
- if(currentImage != NULL){
- cvReleaseImage(¤tImage);
+ if(m_currentImage != NULL){
+ cvReleaseImage(&m_currentImage);
}
- if(resultImage != NULL){
- cvReleaseImage(&resultImage);
+ if(m_resultImage != NULL){
+ cvReleaseImage(&m_resultImage);
}
- if(outputImage != NULL){
- cvReleaseImage(&outputImage);
+ if(m_outputImage != NULL){
+ cvReleaseImage(&m_outputImage);
}
//if(backgroundImage != NULL){
// cvReleaseImage(&backgroundImage);
//}
- g_temp_w = m_img_orig.width;
- g_temp_h = m_img_orig.height;
+ m_temp_w = m_img_orig.width;
+ m_temp_h = m_img_orig.height;
}
@@ -495,8 +347,106 @@
}
*/
+//
+// æåãã¨ã«è©ä¾¡ãã
+//
+void BackGroundSubtractionSimple::colorDifference( void )
+{
+
+ // ç»åãçæãã
+ IplImage *differenceImage = cvCreateImage(cvSize(m_currentImage->width, m_currentImage->height), IPL_DEPTH_8U, 3); // å·®åç»åç¨IplImage
+ IplImage *differenceRImage = cvCreateImage(cvSize(m_currentImage->width, m_currentImage->height), IPL_DEPTH_8U, 1); // Rå¤ã®å·®åç¨IplImage
+ IplImage *differenceGImage = cvCreateImage(cvSize(m_currentImage->width, m_currentImage->height), IPL_DEPTH_8U, 1); // Gå¤ã®å·®åç¨IplImage
+ IplImage *differenceBImage = cvCreateImage(cvSize(m_currentImage->width, m_currentImage->height), IPL_DEPTH_8U, 1); // Bå¤ã®å·®åç¨IplImage
+ // ç¾å¨ã®èæ¯ã¨ã®å·®ã®çµ¶å¯¾å¤ãæåãã¨ã«åã
+ cvAbsDiff( m_currentImage, m_backgroundImage, differenceImage );
+ // é¾å¤å¦çãè¡ã
+ cvThreshold( differenceImage, differenceImage, m_nThresholdLv, THRESHOLD_MAX_VALUE, CV_THRESH_BINARY );
+
+ // æåãã¨ã®ç»åã«åå²ãã
+ cvSplit( differenceImage, differenceBImage, differenceGImage, differenceRImage, NULL );
+
+ // ORã§åæãã
+ cvOr( differenceRImage, differenceGImage, m_resultImage );
+ cvOr( differenceBImage, m_resultImage, m_resultImage );
+
+ // ã¡ã¢ãªã解æ¾ãã
+ cvReleaseImage( &differenceImage );
+ cvReleaseImage( &differenceRImage );
+ cvReleaseImage( &differenceGImage );
+ cvReleaseImage( &differenceBImage );
+
+}
+
+//
+// L*a*b*ã§è·é¢ãè©ä¾¡ãã
+//
+void BackGroundSubtractionSimple::labDifference( void )
+{
+
+ // ç»åãçæãã
+ IplImage *currentLabImage = cvCreateImage( cvSize(m_currentImage->width, m_currentImage->height),IPL_DEPTH_32F, 3 ); // ç¾å¨ã®ç»åãL*a*b*ã«å¤æããç»åç¨IplImage
+ IplImage *backgroundLabImage = cvCreateImage( cvSize(m_currentImage->width, m_currentImage->height), IPL_DEPTH_32F, 3 ); // èæ¯ãL*a*b*ã«å¤æããç»åç¨IplImage
+ IplImage *differenceLabImage = cvCreateImage( cvSize(m_currentImage->width, m_currentImage->height), IPL_DEPTH_32F, 3 ); // å·®åç»åç¨IplImage
+ IplImage *differenceLImage = cvCreateImage( cvSize(m_currentImage->width, m_currentImage->height), IPL_DEPTH_32F, 1 ); // L*å¤ã®å·®åç¨IplImage
+ IplImage *differenceAImage = cvCreateImage( cvSize(m_currentImage->width, m_currentImage->height), IPL_DEPTH_32F, 1 ); // a*å¤ã®å·®åç¨IplImage
+ IplImage *differenceBImage = cvCreateImage( cvSize(m_currentImage->width, m_currentImage->height), IPL_DEPTH_32F, 1 ); // b*å¤ã®å·®åç¨IplImage
+ IplImage *sqrDifferenceImage = cvCreateImage( cvSize(m_currentImage->width, m_currentImage->height), IPL_DEPTH_32F, 1 ); // è·é¢ç®åºç¨IplImage
+
+ // ç¾å¨ã®ç»åã¨èæ¯ãå
±ã« CIE L*a*b* ã«å¤æ
+ cvConvertScale( m_currentImage, currentLabImage, SCALE );
+ cvConvertScale( m_backgroundImage, backgroundLabImage, SCALE );
+ cvCvtColor( currentLabImage, currentLabImage, CV_BGR2Lab );
+ cvCvtColor( backgroundLabImage, backgroundLabImage, CV_BGR2Lab );
+
+ // è·é¢ã®äºä¹ãè¨ç®ãã
+ cvSub( currentLabImage, backgroundLabImage, differenceLabImage );
+ cvPow( differenceLabImage, differenceLabImage, 2 );
+
+ // æåãã¨ã®ç»åã«åå²ãã
+ cvSplit( differenceLabImage, differenceLImage, differenceAImage, differenceBImage, NULL );
+
+ cvCopy( differenceLImage, sqrDifferenceImage );
+ cvAdd( differenceAImage, sqrDifferenceImage, sqrDifferenceImage );
+ cvAdd( differenceBImage, sqrDifferenceImage, sqrDifferenceImage );
+
+ // é¾å¤å¦çãè¡ã
+ cvThreshold( sqrDifferenceImage, m_resultImage, m_nThresholdLv * m_nThresholdLv, THRESHOLD_MAX_VALUE, CV_THRESH_BINARY );
+
+ // ã¡ã¢ãªã解æ¾ãã
+ cvReleaseImage( ¤tLabImage );
+ cvReleaseImage( &backgroundLabImage );
+ cvReleaseImage( &differenceLabImage );
+ cvReleaseImage( &differenceLImage );
+ cvReleaseImage( &differenceAImage );
+ cvReleaseImage( &differenceBImage );
+ cvReleaseImage( &sqrDifferenceImage );
+}
+
+//
+// ã°ã¬ã¼ã¹ã±ã¼ã«ã§è©ä¾¡ãã
+//
+void BackGroundSubtractionSimple::grayScaleDifference( void )
+{
+
+ // ç»åãçæãã
+ IplImage *differenceImage = cvCreateImage( cvSize(m_currentImage->width, m_currentImage->height), IPL_DEPTH_8U, 3 ); // å·®åç»åç¨IplImage
+
+ // ç¾å¨ã®èæ¯ã¨ã®å·®ã®çµ¶å¯¾å¤ãæåãã¨ã«åã
+ cvAbsDiff( m_currentImage, m_backgroundImage, differenceImage );
+
+ // BGRããã°ã¬ã¼ã¹ã±ã¼ã«ã«å¤æãã
+ cvCvtColor( differenceImage, m_resultImage, CV_BGR2GRAY );
+
+ // ã°ã¬ã¼ã¹ã±ã¼ã«ãã2å¤ã«å¤æãã
+ cvThreshold( m_resultImage, m_resultImage, m_nThresholdLv, THRESHOLD_MAX_VALUE, CV_THRESH_BINARY );
+
+ // ã¡ã¢ãªã解æ¾ãã
+ cvReleaseImage( &differenceImage );
+}
+
extern "C"
{
More information about the openrtm-commit
mailing list