[openrtm-commit:01134] r104 - in branches/newCMakeForVC2010/ImageProcessing/opencv/components: . ImageSubstraction/include/ImageSubstraction ImageSubstraction/src RockPaperScissors RockPaperScissors/include RockPaperScissors/include/RockPaperScissors RockPaperScissors/src

openrtm @ openrtm.org openrtm @ openrtm.org
2013年 11月 29日 (金) 15:24:42 JST


Author: kawauchi
Date: 2013-11-29 15:24:42 +0900 (Fri, 29 Nov 2013)
New Revision: 104

Removed:
   branches/newCMakeForVC2010/ImageProcessing/opencv/components/Houghline/
Modified:
   branches/newCMakeForVC2010/ImageProcessing/opencv/components/ImageSubstraction/include/ImageSubstraction/ImageSubstraction.h
   branches/newCMakeForVC2010/ImageProcessing/opencv/components/ImageSubstraction/src/ImageSubstraction.cpp
   branches/newCMakeForVC2010/ImageProcessing/opencv/components/RockPaperScissors/RockPaperScissors.conf
   branches/newCMakeForVC2010/ImageProcessing/opencv/components/RockPaperScissors/include/LabellingW.h
   branches/newCMakeForVC2010/ImageProcessing/opencv/components/RockPaperScissors/include/RockPaperScissors/RockPaperScissors.h
   branches/newCMakeForVC2010/ImageProcessing/opencv/components/RockPaperScissors/src/RockPaperScissors.cpp
Log:
For replacement, remove Hough component . refs #2704

Modified: branches/newCMakeForVC2010/ImageProcessing/opencv/components/ImageSubstraction/include/ImageSubstraction/ImageSubstraction.h
===================================================================
--- branches/newCMakeForVC2010/ImageProcessing/opencv/components/ImageSubstraction/include/ImageSubstraction/ImageSubstraction.h	2013-11-14 07:48:22 UTC (rev 103)
+++ branches/newCMakeForVC2010/ImageProcessing/opencv/components/ImageSubstraction/include/ImageSubstraction/ImageSubstraction.h	2013-11-29 06:24:42 UTC (rev 104)
@@ -24,9 +24,7 @@
 #include <highgui.h>
 
 #define	NUM_OF_BACKGROUND_FRAMES	50	//	”wŒiƒ‚ƒfƒ‹‚𐶐¬‚·‚é‚Ì‚ÉŽg—p‚·‚é‰æ‘œ‚Ì–‡”
-#define	THRESHOLD_COEFFICIENT		5.0	//	臒l‚ðŒˆ‚ß‚éÛ‚ÉŽg—p‚·‚é•W€•Î·‚É‚©‚¯‚鐔
 
-#define	CONSTANT_THRESHOLD	20	//	‰æ‘œ‚Å1‚‚Ì臒l‚ðŽg‚¤Û‚Ì臒l
 #define CONSTANT_MODE		0	//	‰æ‘œ‘S‘Ì‚Å1‚‚Ì臒l‚ð—p‚¢‚éƒtƒ‰ƒO’l
 #define DYNAMIC_MODE		1	//	‰æ‘f‚²‚Æ‚É臒l‚ðÝ‚¯‚éƒtƒ‰ƒO’l
 
@@ -236,6 +234,12 @@
   // <rtc-template block="config_declare">
   /*!
    * 
+   * - Name:  cont_mode
+   * - DefaultValue: b
+   */
+  char m_cont_mode;
+  /*!
+   * 
    * - Name:  img_height
    * - DefaultValue: 240
    */
@@ -246,7 +250,19 @@
    * - DefaultValue: 320
    */
   int m_img_width;
-
+  /*!
+   * 
+   * - Name:  thre_coefficient
+   * - DefaultValue: 5.0
+   */
+  double m_thre_coefficient;
+  /*!
+   * 
+   * - Name:  constant_thre
+   * - DefaultValue: 20
+   */
+  int m_constant_thre;
+  
   // </rtc-template>
 
   // DataInPort declaration

Modified: branches/newCMakeForVC2010/ImageProcessing/opencv/components/ImageSubstraction/src/ImageSubstraction.cpp
===================================================================
--- branches/newCMakeForVC2010/ImageProcessing/opencv/components/ImageSubstraction/src/ImageSubstraction.cpp	2013-11-14 07:48:22 UTC (rev 103)
+++ branches/newCMakeForVC2010/ImageProcessing/opencv/components/ImageSubstraction/src/ImageSubstraction.cpp	2013-11-29 06:24:42 UTC (rev 104)
@@ -25,19 +25,26 @@
     "language",          "C++",
     "lang_type",         "compile",
     // Configuration variables
+    "conf.default.control_mode", "b",
     "conf.default.image_height", "240",
     "conf.default.image_width", "320",
+    "conf.default.threshold_coefficient", "5.0",
+    "conf.default.constant_threshold", "20",
     // Widget
+    "conf.__widget__.control_mode", "radio",
     "conf.__widget__.image_height", "text",
     "conf.__widget__.image_width", "text",
+    "conf.__widget__.threshold_coefficient", "text",
+    "conf.__widget__.constant_threshold", "slider.1",
     // Constraints
+    "conf.__constraints__.control_mode", "(b,m)",
+    "conf.__constraints__.constant_threshold", "0<=x<=255",
     ""
   };
 // </rtc-template>
 
 int ImageSubstraction_count = 0;
-int key;		//	ƒL[“ü—Í—p‚̕ϐ”
-int	mode = 0;	// 0: ‰æ‘f‚²‚ƂɈقȂé臒l / 1: ‰æ‘œ‘S‘̂ňê‚‚Ì臒l
+int	mode = DYNAMIC_MODE;	// DYNAMIC_MODE: ‰æ‘f‚²‚ƂɈقȂé臒l / CONSTANT_MODE: ‰æ‘œ‘S‘̂ňê‚‚Ì臒l
 int g_temp_w = 0;
 int g_temp_h = 0;
 
@@ -46,9 +53,9 @@
 //char *windowNameBackground = "Background";	//	”wŒi‰æ‘œ‚ð•\Ž¦‚·‚éƒEƒBƒ“ƒhƒE‚Ì–¼‘O
 //char *windowNameThreshold = "Threshold";	//	臒l‚ð•\Ž¦‚·‚éƒEƒBƒ“ƒhƒE‚Ì–¼‘O
 
-char *mode_str[2] = {
-	"‰æ‘f’PˆÊ",
-	"‰æ‘œ‚ňê‚Â"
+std::string mode_str[2] = {
+	"DYNAMIC_MODE",   //‰æ‘f’PˆÊ
+	"CONSTANT_MODE"    //‰æ‘œ‚ňê‚Â
 };
 
 IplImage *backgroundAverageImage = NULL;	//	”wŒi‚Ì•½‹Ï’l•Û‘¶—pIplImage
@@ -83,7 +90,7 @@
 //		num  : ”wŒiƒ‚ƒfƒ‹‚𐶐¬‚·‚é‚Ì‚ÉŽg—p‚·‚é‰æ‘œ‚Ì–‡”
 //		size : ‰æ‘œƒTƒCƒY
 //
-void initializeBackgroundModel( int num, CvSize size ){
+void initializeBackgroundModel( int num, CvSize size, double thre_coefficient ){
 	int i;
 
 	// ˆÈ‘O‚Ì”wŒiî•ñ‚ª‚ ‚ê‚ΔjŠü
@@ -103,15 +110,15 @@
 	cvSetZero( acc2 );
 
 	//	‰æ‘œî•ñ‚Ì’~Ï
-	printf( "”wŒiŽæ“¾’†...\n" );
+	printf( "Getting background...\n" ); //”wŒiŽæ“¾’†
 	//IplImage *frameImage;
 	for( i = 0; i < num; i++ ){
 		//frameImage = cvQueryFrame( capture );
 		cvAcc( originalImage, acc );
 		cvSquareAcc( originalImage, acc2 );
-		printf( "%d –‡’† %d –‡–Ú\n", num, i + 1 );
+    printf( "%d / %d image\n", i + 1, num );
 	}
-	printf( "”wŒiŽæ“¾Š®—¹\n" );
+	printf( "Completion!\n" ); //”wŒiŽæ“¾Š®—¹
 
 	//	cvAddS, cvSubS ‚Í‚ ‚邪 cvMulS ‚Í‚È‚¢‚̂ŁAcvConvertScale ‚ðŽg‚¤
 	cvConvertScale( acc, acc, 1.0 / num );		// •½‹Ï
@@ -132,7 +139,7 @@
 
 	//	臒l‚ðŒvŽZ‚·‚é
 	backgroundThresholdImage = cvCreateImage( size, IPL_DEPTH_8U, 3 );
-	cvConvertScale( sd, backgroundThresholdImage, THRESHOLD_COEFFICIENT );
+	cvConvertScale( sd, backgroundThresholdImage, thre_coefficient );
 
 	//	ƒƒ‚ƒŠ‚ð‰ð•ú‚·‚é
 	cvReleaseImage( &acc );
@@ -149,7 +156,7 @@
     // <rtc-template block="initializer">
   : RTC::DataFlowComponentBase(manager),
     m_img_origIn("original_image", m_img_orig),
-	m_keyIn("Key", m_key),
+    m_keyIn("Key", m_key),
     m_img_captureOut("capture_image", m_img_capture),
     m_img_resultOut("result_image", m_img_result),
     m_img_backOut("back_image", m_img_back),
@@ -192,8 +199,11 @@
 
   // <rtc-template block="bind_config">
   // Bind variables and configuration variable
+  bindParameter("control_mode", m_cont_mode, "b");
   bindParameter("image_height", m_img_height, "240");
   bindParameter("image_width", m_img_width, "320");
+  bindParameter("threshold_coefficient", m_thre_coefficient, "5.0");
+  bindParameter("constant_threshold", m_constant_thre, "20");
   // </rtc-template>
   
   return RTC::RTC_OK;
@@ -231,6 +241,9 @@
 	outputImage = NULL;
 	resultImage = NULL;
 	differenceImage = NULL;
+	
+  //臒l‚̏‰ŠúÝ’è‚ð•\Ž¦
+  printf( "threshold: %s\n", mode_str[1-mode].c_str() );
 
 	return RTC::RTC_OK;
 }
@@ -258,7 +271,23 @@
 
 RTC::ReturnCode_t ImageSubstraction::onExecute(RTC::UniqueId ec_id)
 {	
-	
+	//	ƒL[“ü—Í”»’è
+  if(m_keyIn.isNew()){
+    m_keyIn.read();
+
+	  if( m_cont_mode == 'b' ){
+		  //	'b'ƒL[‚ª‰Ÿ‚³‚ꂽ‚ç‚»‚ÌŽž“_‚ł̉摜‚ð”wŒi‰æ‘œ‚Æ‚·‚é
+		  initializeBackgroundModel( NUM_OF_BACKGROUND_FRAMES, cvSize(m_img_width, m_img_height), m_thre_coefficient);
+		
+		  printf( "Background image update\n" );   //”wŒiî•ñXV
+		
+	  } else if( m_cont_mode == 'm' ){
+		  //	'm'ƒL[‚ª‰Ÿ‚³‚ꂽ‚ç臒l‚̐ݒè•û–@‚ð•ÏX‚·‚é
+		  mode = 1 - mode;
+		  printf( "threshold: %s\n", mode_str[mode].c_str() );
+	  }
+	}
+				
 	//‰Šú’l‚ðŽæ“¾‚·‚éB
 	if(ImageSubstraction_count == 0 && m_img_origIn.isNew()) {
 		
@@ -295,7 +324,7 @@
 				resultImage = cvCreateImage(cvSize(m_img_orig.width, m_img_orig.height),IPL_DEPTH_8U, 1);
 			}
 
-			initializeBackgroundModel( NUM_OF_BACKGROUND_FRAMES, cvSize(m_img_orig.width, m_img_orig.height) );
+			initializeBackgroundModel( NUM_OF_BACKGROUND_FRAMES, cvSize(m_img_orig.width, m_img_orig.height) , m_thre_coefficient);
 			
 			ImageSubstraction_count = 1;
 			g_temp_w = m_img_orig.width;
@@ -325,21 +354,16 @@
 				outputImage = cvCreateImage(cvSize(m_img_orig.width, m_img_orig.height), IPL_DEPTH_8U, 3);
 			}
 
-			if(m_keyIn.isNew()) {
-				m_keyIn.read();
-				key = (int)m_key.data;
-			}
-
 			memcpy(originalImage->imageData,(void *)&(m_img_orig.pixels[0]), m_img_orig.pixels.length());
 
 			//	Œ»Ý‚Ì”wŒi‚Ƃ̍·‚̐â‘Î’l‚𐬕ª‚²‚Æ‚ÉŽæ‚é
 			cvAbsDiff( originalImage, backgroundAverageImage, differenceImage );
 			
 			//	Sub ‚̓}ƒCƒiƒX‚É‚È‚Á‚½‚ç0‚ɐ؂è‹l‚ß‚Ä‚­‚ê‚é
-			if( mode == 0 ){
+			if( mode == DYNAMIC_MODE ){
 				cvSub( differenceImage, backgroundThresholdImage, differenceImage );
 			} else{
-				cvSubS( differenceImage, cvScalarAll( CONSTANT_THRESHOLD ), differenceImage );
+				cvSubS( differenceImage, cvScalarAll( m_constant_thre ), differenceImage );
 			}
 			
 			//	differenceImage ‚Ì—v‘f‚ª1‚‚łà0ˆÈã‚¾‚Á‚½‚ç‘OŒi
@@ -395,26 +419,10 @@
 			m_img_thresholdOut.write();
 			
 			cvReleaseImage( &tmp );
-			//	ƒL[“ü—Í”»’è
-			cvWaitKey( 1 );
-			//key = (int)m_key.data;
 
-			if( key == 'b' ){
-				//	'b'ƒL[‚ª‰Ÿ‚³‚ꂽ‚ç‚»‚ÌŽž“_‚ł̉摜‚ð”wŒi‰æ‘œ‚Æ‚·‚é
-				initializeBackgroundModel( NUM_OF_BACKGROUND_FRAMES, cvSize(m_img_width, m_img_height));
-				
-				printf( "”wŒiî•ñXV\n" );
-				
-			} else if( key == 'm' ){
-				//	'm'ƒL[‚ª‰Ÿ‚³‚ꂽ‚ç臒l‚̐ݒè•û–@‚ð•ÏX‚·‚é
-				mode = 1 - mode;
-				printf( "臒l: %s\n", mode_str[mode] );
-			}
-
 			cvReleaseImage(&originalImage);
 			cvReleaseImage(&outputImage);
 			
-			key = '0';
 			g_temp_w = m_img_orig.width;
 			g_temp_h = m_img_orig.height;
 		

Modified: branches/newCMakeForVC2010/ImageProcessing/opencv/components/RockPaperScissors/RockPaperScissors.conf
===================================================================
--- branches/newCMakeForVC2010/ImageProcessing/opencv/components/RockPaperScissors/RockPaperScissors.conf	2013-11-14 07:48:22 UTC (rev 103)
+++ branches/newCMakeForVC2010/ImageProcessing/opencv/components/RockPaperScissors/RockPaperScissors.conf	2013-11-29 06:24:42 UTC (rev 104)
@@ -130,5 +130,5 @@
 ##
 ## The execution cycle of ExecutionContext
 ##
-exec_cxt.periodic.rate:1000.0
+exec_cxt.periodic.rate:2000.0
 

Modified: branches/newCMakeForVC2010/ImageProcessing/opencv/components/RockPaperScissors/include/LabellingW.h
===================================================================
--- branches/newCMakeForVC2010/ImageProcessing/opencv/components/RockPaperScissors/include/LabellingW.h	2013-11-14 07:48:22 UTC (rev 103)
+++ branches/newCMakeForVC2010/ImageProcessing/opencv/components/RockPaperScissors/include/LabellingW.h	2013-11-29 06:24:42 UTC (rev 104)
@@ -8,7 +8,7 @@
 #include "Labeling.h"
 
 #define Label LabelingBS
-/*
+
 Label *createLabeling(){
 	return new LabelingBS();
 }
@@ -26,5 +26,6 @@
 void releaseLabeling(Label *label){
 	delete label;
 }
-*/
-#endif LABELINGW_H
\ No newline at end of file
+
+#endif //LABELINGW_H
+

Modified: branches/newCMakeForVC2010/ImageProcessing/opencv/components/RockPaperScissors/include/RockPaperScissors/RockPaperScissors.h
===================================================================
--- branches/newCMakeForVC2010/ImageProcessing/opencv/components/RockPaperScissors/include/RockPaperScissors/RockPaperScissors.h	2013-11-14 07:48:22 UTC (rev 103)
+++ branches/newCMakeForVC2010/ImageProcessing/opencv/components/RockPaperScissors/include/RockPaperScissors/RockPaperScissors.h	2013-11-29 06:24:42 UTC (rev 104)
@@ -19,33 +19,24 @@
 #include <rtm/idl/ExtendedDataTypesSkel.h>
 #include <rtm/idl/InterfaceDataTypesSkel.h>
 
-// OpenCVHeadƒtƒ@ƒCƒ‹‚ÌIncluding
+// OpenCVHeadファイルのIncluding
 #include <cv.h>
 #include <cxcore.h>
 #include <highgui.h>
 
-#include "LabellingW.h"
+#include <string>
+#include "Labeling.h"
 
-#define	ITERATIONS	4	//	–c’£AŽûk‚̉ñ”
+//肌色抽出用閾値
+#define HMAX 20			//	H値の上限の閾値
+#define HMIN 0			//	H値の下限の閾値
+#define SMAX 255*1		//	S値の上限の閾値
+#define SMIN 255*0.2	//	S値の下限の閾値
+#define VMAX 255*1.0	//	V値の上限の閾値
+#define VMIN 255*0		//	V値の下限の閾値
 
-//”§F’Šo—p臒l
-#define HMAX 20			//	H’l‚̏ãŒÀ‚Ì臒l
-#define HMIN 0			//	H’l‚̉ºŒÀ‚Ì臒l
-#define SMAX 255*1		//	S’l‚̏ãŒÀ‚Ì臒l
-#define SMIN 255*0.2	//	S’l‚̉ºŒÀ‚Ì臒l
-#define VMAX 255*1.0	//	V’l‚̏ãŒÀ‚Ì臒l
-#define VMIN 255*0		//	V’l‚̉ºŒÀ‚Ì臒l
+#define IGNORE_SIZE 1000	//無視する領域サイズ(ラベリング用)
 
-//ƒWƒƒƒ“ƒPƒ“”»’è—p臒l
-#define ROCKMAX 1.0		//	ƒO[‚Æ”»’è‚·‚éãŒÀ‚Ì臒l
-#define ROCKMIN 0.85	//	ƒO[‚Æ”»’è‚·‚鉺ŒÀ‚Ì臒l
-#define SCISSORMAX 0.85	//	ƒ`ƒ‡ƒL‚Æ”»’è‚·‚éãŒÀ‚Ì臒l
-#define SCISSORMIN 0.7	//	ƒ`ƒ‡ƒL‚Æ”»’è‚·‚鉺ŒÀ‚Ì臒l
-#define PAPERMAX 0.7	//	ƒp[‚Æ”»’è‚·‚éãŒÀ‚Ì臒l
-#define PAPERMIN 0.5	//	ƒp[‚Æ”»’è‚·‚鉺ŒÀ‚Ì臒l
-
-#define IGNORE_SIZE 1000	//–³Ž‹‚·‚é—̈æƒTƒCƒY(ƒ‰ƒxƒŠƒ“ƒO—p)
-
 // Service implementation headers
 // <rtc-template block="service_impl_h">
 
@@ -252,18 +243,48 @@
   // <rtc-template block="config_declare">
   /*!
    * 
-   * - Name:  img_height
-   * - DefaultValue: 240
+   * - Name:  rock_max
+   * - DefaultValue: 1.0
    */
-  int m_img_height;
+  double m_rock_max;
   /*!
    * 
-   * - Name:  img_width
-   * - DefaultValue: 320
+   * - Name:  rock_min
+   * - DefaultValue: 0.85
    */
-  int m_img_width;
+  double m_rock_min;
   /*!
    * 
+   * - Name:  scissor_max
+   * - DefaultValue: 0.85
+   */
+  double m_scissor_max;
+  /*!
+   * 
+   * - Name:  scissor_min
+   * - DefaultValue: 0.7
+   */
+  double m_scissor_min;
+  /*!
+   * 
+   * - Name:  paper_max
+   * - DefaultValue: 0.7
+   */
+  double m_paper_max;
+  /*!
+   * 
+   * - Name:  paper_min
+   * - DefaultValue: 0.5
+   */
+  double m_paper_min;
+  /*!
+   * 
+   * - Name:  iterations
+   * - DefaultValue: 4
+   */
+  int m_iterations;
+  /*!
+   * 
    * - Name:  out_mode
    * - DefaultValue: 1
    */
@@ -288,6 +309,11 @@
    */
   OutPort<RTC::CameraImage> m_img_outputOut;
   
+  RTC::TimedString m_result;
+  /*!
+   */
+  OutPort<RTC::TimedString> m_resultOut;
+  
   // </rtc-template>
 
   // CORBA Port declaration
@@ -313,7 +339,18 @@
   // <rtc-template block="private_operation">
   
   // </rtc-template>
+  
+  void extractSkinColor( void );
+  void interpolate( void );
+  int  pickupMaxArea( void );
+  void createConvexHull( int handarea, CvPoint **handpoint, int **hull,
+					  CvMat *pointMatrix, CvMat *hullMatrix );
+  void drawConvexHull( CvPoint *handpoint, int *hull, int hullcount );
+  int  calcConvexHullArea( CvPoint *handpoint, int *hull, int hullcount );
+  void decide( int handarea, int hullarea );
+  
 	int dummy;
+	std::string m_prev_judge;   //前回の判定 グー / チョキ / パー
 	
 	IplImage* m_frame_image;
 	IplImage* m_image_buff;

Modified: branches/newCMakeForVC2010/ImageProcessing/opencv/components/RockPaperScissors/src/RockPaperScissors.cpp
===================================================================
--- branches/newCMakeForVC2010/ImageProcessing/opencv/components/RockPaperScissors/src/RockPaperScissors.cpp	2013-11-14 07:48:22 UTC (rev 103)
+++ branches/newCMakeForVC2010/ImageProcessing/opencv/components/RockPaperScissors/src/RockPaperScissors.cpp	2013-11-29 06:24:42 UTC (rev 104)
@@ -8,10 +8,10 @@
  */
 
 #include "RockPaperScissors.h"
+#define Label LabelingBS
 
 using namespace std;
 
-
 CvCapture *capture = NULL;
 
 // Module specification
@@ -30,14 +30,31 @@
     "language",          "C++",
     "lang_type",         "compile",
     // Configuration variables
-    "conf.default.image_height", "240",
-    "conf.default.image_width", "320",
+    "conf.default.rock_max", "1.0",
+    "conf.default.rock_min", "0.85",
+    "conf.default.scissor_max", "0.85",
+    "conf.default.scissor_min", "0.7",
+    "conf.default.paper_max", "0.7",
+    "conf.default.paper_min", "0.5",
+    "conf.default.iterations", "4",
     "conf.default.out_mode", "1",
     // Widget
-    "conf.__widget__.image_height", "text",
-    "conf.__widget__.image_width", "text",
-    "conf.__widget__.out_mode", "text",
+    "conf.__widget__.rock_max", "text",
+    "conf.__widget__.rock_min", "text",
+    "conf.__widget__.scissor_max", "text",
+    "conf.__widget__.scissor_min", "text",
+    "conf.__widget__.paper_max", "text",
+    "conf.__widget__.paper_min", "text",
+    "conf.__widget__.iterations", "text",
+    "conf.__widget__.out_mode", "radio",
     // Constraints
+    "conf.__constraints__.rock_max", "0<=x<=1.0",
+    "conf.__constraints__.rock_min", "0<=x<=1.0",
+    "conf.__constraints__.scissor_max", "0<=x<=1.0",
+    "conf.__constraints__.scissor_min", "0<=x<=1.0",
+    "conf.__constraints__.paper_max", "0<=x<=1.0",
+    "conf.__constraints__.paper_min", "0<=x<=1.0",
+    "conf.__constraints__.out_mode", "(0,1)",
     ""
   };
 // </rtc-template>
@@ -60,200 +77,6 @@
 	delete label;
 }
 
-	//
-	//	”§F‚𒊏o‚·‚é
-	//
-	//	ˆø”:
-	//		frameImage : ƒLƒƒƒvƒ`ƒƒ‚µ‚½‰æ‘œ—pIplImage
-	//		hsvImage   : HSV‰æ‘œ—pIplImage
-	//		skinImage  : ”§F’Šo‰æ‘œ—pIplImage
-	//
-void extractSkinColor( IplImage *frameImage, IplImage *hsvImage, IplImage *skinImage ) {
-	CvScalar color;		//	HSV•\FŒn‚Å•\‚µ‚½F
-	unsigned char h;	//	H¬•ª
-	unsigned char s;	//	S¬•ª
-	unsigned char v;	//	V¬•ª
-	
-	//	BGR‚©‚çHSV‚É•ÏŠ·‚·‚é
-	
-	cvCvtColor( frameImage, hsvImage, CV_BGR2HSV );
-	
-	//”§F’Šo
-	for( int x = 0; x < skinImage->width; x++ ) {
-		for( int y = 0 ; y < skinImage->height; y++ ) {
-
-			color = cvGet2D( hsvImage, y, x );
-			h = color.val[0];
-			s = color.val[1];
-			v = color.val[2];
-
-			if( h <= HMAX && h >= HMIN &&
-				s <= SMAX && s >= SMIN &&
-					v <= VMAX && v >= VMIN ) {
-				//	”§F‚̏ꍇ
-				cvSetReal2D( skinImage, y, x, 255 );
-			} else {
-				cvSetReal2D( skinImage, y, x, 0 );
-			}
-		}
-	}
-}
-
-	//
-	//	Œ‡‘¹—̈æ‚ð•âŠÔ‚·‚é
-	//
-	//	ˆø”:
-	//		skinImage : ”§F’Šo‰æ‘œ—pIplImage
-	//		temp      : ˆêŽž•Û‘¶—pIplImage
-	//
-void interpolate( IplImage *skinImage, IplImage *temp ) {
-	//–c’£‚ðITERATIONS‰ñs‚¤
-	cvDilate( skinImage, temp, NULL, ITERATIONS );
-
-	//Žûk‚ðITERATIONS‰ñs‚¤
-	cvErode( temp, skinImage, NULL, ITERATIONS );
-}
-
-	//
-	//	Å‘å—̈æ(Žè—̈æ)‚Ì’Šo‚ðs‚¤
-	//
-	//	ˆø”:
-	//		skinImage       : ”§F’Šo‰æ‘œ—pIplImage
-	//		label           : ƒ‰ƒxƒŠƒ“ƒO‚µ‚½Œ‹‰Ê
-	//		convexHullImage : ConvexHull‰æ‘œ—pIplImage
-	//
-	//	–ß‚è’l:
-	//		Žè—̈æ‚̖ʐÏ
-	//
-int pickupMaxArea(IplImage *skinImage, IplImage *label, IplImage *convexHullImage ) {
-
-	int handarea = 0;	//	Žè—̈æ‚̖ʐÏ
-
-	for(int x = 0; x < skinImage->width; x++ ) {
-		for( int y=0; y < skinImage->height; y++ ) {
-			if( cvGetReal2D( label, y, x ) == 1 ) {
-				//	Å‘å—̈悾‚Á‚½ê‡
-				handarea++;
-				cvSet2D( convexHullImage, y, x, CV_RGB( 255, 255, 255 ) );
-			} else {
-				cvSetReal2D( skinImage, y, x, 0 );
-				cvSet2D( convexHullImage, y, x, CV_RGB( 0, 0, 0 ) );
-			}
-		}
-	}
-	return handarea;
-}
-
-	//
-	//	ConvexHull‚𐶐¬‚·‚é
-	//
-	//	ˆø”:
-	//		skinImage   : ”§F’Šo‰æ‘œ—pIplImage
-	//		handarea    : Žè—̈æ‚̖ʐÏ(“_‚̐”)
-	//		handpoint   : Žè—̈æ“à‚Ì“_‚̍À•W”z—ñ‚ւ̃|ƒCƒ“ƒ^
-	//		hull        : ConvexHull‚Ì’¸“_‚Ìhandpoint‚É‚¨‚¯‚éindex”ԍ†‚ւ̃|ƒCƒ“ƒ^
-	//		pointMatrix : Žè—̈æ—ps—ñ‚ւ̃|ƒCƒ“ƒ^
-	//		hullMatrix  : ConvexHull—ps—ñ‚ւ̃|ƒCƒ“ƒ^
-	//
-void createConvexHull(IplImage *skinImage, int handarea, CvPoint **handpoint, int **hull,
-					  CvMat *pointMatrix, CvMat *hullMatrix ) {
-	int i=0;
-
-	//	ConvexHull‚ðŒvŽZ‚·‚邽‚ß‚É•K—v‚ȍs—ñ‚𐶐¬‚·‚é
-	*handpoint=( CvPoint * )malloc( sizeof( CvPoint ) * handarea );
-	*hull = ( int * )malloc( sizeof( int ) * handarea );
-	*pointMatrix = cvMat( 1, handarea, CV_32SC2, *handpoint );
-	*hullMatrix = cvMat( 1, handarea, CV_32SC1, *hull );
-
-	for( int x = 0; x < skinImage->width; x++ ) {
-		for(  int y = 0; y < skinImage->height; y++ ) {
-			if( cvGetReal2D( skinImage, y, x ) == 255 ) {
-				( *handpoint )[i].x = x;
-				( *handpoint )[i].y = y;
-				i++;
-			}
-		}
-	}
-
-	//	ConvexHull‚𐶐¬‚·‚é
-	cvConvexHull2( pointMatrix, hullMatrix, CV_CLOCKWISE, 0 );
-}
-
-	//
-	//	ConvexHull‚ð•`‰æ‚·‚é
-	//
-	//	ˆø”:
-	//		convexHullImage : ConvexHull‰æ‘œ—pIplImage
-	//		handpoint       : Žè—̈æ“à‚Ì“_‚̍À•W”z—ñ
-	//		hull            : ConvexHull‚Ì’¸“_‚Ìhandpoint‚É‚¨‚¯‚éindex”ԍ†
-	//		hullcount       : ConvexHull‚Ì’¸“_‚̐”
-	//
-void drawConvexHull(IplImage *convexHullImage, CvPoint *handpoint, int *hull, int hullcount ) {
-	CvPoint pt0 = handpoint[hull[hullcount-1]];
-	for( int i = 0; i < hullcount; i++ ) {
-		CvPoint pt = handpoint[hull[i]];
-		cvLine( convexHullImage, pt0, pt, CV_RGB( 0, 255, 0 ) );
-		pt0 = pt;
-	}
-}
-
-	//
-	//	ConvexHull“à‚Ì–ÊÏ‚ð‹‚ß‚é
-	//
-	//	ˆø”:
-	//		convexHullImage : ConvexHull‰æ‘œ—pIplImage
-	//		handpoint       : Žè—̈æ“à‚Ì“_‚̍À•W”z—ñ
-	//		hull            : ConvexHull‚Ì’¸“_‚Ìhandpoint‚É‚¨‚¯‚éindex”ԍ†
-	//		hullcount       : ConvexHull‚Ì’¸“_‚̐”@@
-	//
-	//	–ß‚è’l:
-	//		ConvexHull“à‚̖ʐÏ
-	//
-int calcConvexHullArea( IplImage *convexHullImage, CvPoint *handpoint, int *hull, int hullcount ) {
-
-	//	ConvexHull‚Ì’¸“_‚©‚ç‚È‚és—ñ‚𐶐¬
-	CvPoint *hullpoint = ( CvPoint * )malloc( sizeof( CvPoint ) * hullcount );
-	CvMat hMatrix = cvMat( 1, hullcount, CV_32SC2, hullpoint );
-	for( int i = 0; i < hullcount; i++ ) {
-		hullpoint[i]=handpoint[hull[i]];
-	}
-
-	//	ConvexHull“à‚Ì“_‚̐”‚𐔂¦‚é
-	int hullarea = 0;
-	for( int x = 0; x < convexHullImage->width; x++ ) {
-		for( int y = 0;y < convexHullImage->height; y++ ) {
-			if( cvPointPolygonTest( &hMatrix, cvPoint2D32f( x, y ), 0 ) > 0) {
-				hullarea++;
-			}
-		}
-	}
-
-	free( hullpoint );
-	return hullarea;
-}
-
-	//
-	//	ƒWƒƒƒ“ƒPƒ“‚Ì”»’è‚ðs‚¤
-	//
-	//	ˆø”:
-	//		handarea : Žè—̈æ‚̖ʐÏ
-	//		hullarea : ConvexHull“à‚̖ʐÏ
-	//
-void decide( int handarea, int hullarea ) {
-	double ratio;	//	ConvexHull“à‚̖ʐςɑ΂·‚éŽè—̈æ‚̖ʐς̊„‡
-	
-	ratio=handarea / ( double )hullarea;	
-	printf( "Ratio = %lf\n", ratio );
-
-	if( ratio >= ROCKMIN && ratio <= ROCKMAX ) {
-		printf( "ƒO[\n" );
-	} else if( ratio >= SCISSORMIN && ratio <= SCISSORMAX ) {
-		printf( "ƒ`ƒ‡ƒL\n" );
-	} else if( ratio >= PAPERMIN && ratio <= PAPERMAX ) {
-		printf( "ƒp[\n" );
-	}
-}
-
 /*!
  * @brief constructor
  * @param manager Maneger Object
@@ -262,7 +85,8 @@
     // <rtc-template block="initializer">
   : RTC::DataFlowComponentBase(manager),
     m_img_inputIn("image_input", m_img_input),
-    m_img_outputOut("image_output", m_img_output)
+    m_img_outputOut("image_output", m_img_output),
+    m_resultOut("result", m_result)
 
     // </rtc-template>
 {
@@ -276,7 +100,6 @@
 }
 
 
-
 RTC::ReturnCode_t RockPaperScissors::onInitialize()
 {
   // Registration: InPort/OutPort/Service
@@ -286,6 +109,7 @@
   
   // Set OutPort buffer
   addOutPort("image_output", m_img_outputOut);
+  addOutPort("result", m_resultOut);
   
   // Set service provider to Ports
   
@@ -297,8 +121,13 @@
 
   // <rtc-template block="bind_config">
   // Bind variables and configuration variable
-  bindParameter("image_height", m_img_height, "240");
-  bindParameter("image_width", m_img_width, "320");
+  bindParameter("rock_max", m_rock_max, "1.0");
+  bindParameter("rock_min", m_rock_min, "0.85");
+  bindParameter("scissor_max", m_scissor_max, "0.85");
+  bindParameter("scissor_min", m_scissor_min, "0.7");
+  bindParameter("paper_max", m_paper_max, "0.7");
+  bindParameter("paper_min", m_paper_min, "0.5");
+  bindParameter("iterations", m_iterations, "4");
   bindParameter("out_mode", m_out_mode, "1");
   // </rtc-template>
   
@@ -330,13 +159,14 @@
 RTC::ReturnCode_t RockPaperScissors::onActivated(RTC::UniqueId ec_id)
 {
 
-	m_image_buff = NULL; // “ü—ÍImage
-	m_hsv_buff = NULL; // HSV—p
-	m_convexHull_buff = NULL; // ConvexHull—p
-	m_skin_buff = NULL; // ”§F’Šo—p
-	m_temp_buff = NULL; // ˆêŽž•Û‘¶—p
-	m_label_buff = NULL; // ƒ‰ƒxƒ‹Œ‹‰Ê•Û‘¶—p
-	m_output_buff = NULL; // o—Í—p
+	m_image_buff = NULL; // 入力Image
+	m_hsv_buff = NULL; // HSV用
+	m_convexHull_buff = NULL; // ConvexHull用
+	m_skin_buff = NULL; // 肌色抽出用
+	m_temp_buff = NULL; // 一時保存用
+	m_label_buff = NULL; // ラベル結果保存用
+	m_output_buff = NULL; // 出力用
+	m_prev_judge = "";    // 未判定
 
 	return RTC::RTC_OK;
 }
@@ -372,68 +202,66 @@
 
 RTC::ReturnCode_t RockPaperScissors::onExecute(RTC::UniqueId ec_id)
 {	
-	int key;
-	
-	//Vƒf[ƒ^‚̃`ƒFƒbƒN
+	//新データのチェック
 	if(m_img_inputIn.isNew()){
-		//ƒf[ƒ^‚̓ǂݍž‚Ý
+		//データの読み込み
 		m_img_inputIn.read();
 
-		m_image_buff = cvCreateImage(cvSize(m_img_input.width, m_img_input.height), IPL_DEPTH_8U, 3); // “ü—ÍImage
-		m_hsv_buff = cvCreateImage(cvSize(m_img_input.width, m_img_input.height), IPL_DEPTH_8U, 3); // HSV—p
-		m_convexHull_buff = cvCreateImage(cvSize(m_img_input.width, m_img_input.height), IPL_DEPTH_8U, 3); // ConvexHull—p
-		m_skin_buff = cvCreateImage(cvSize(m_img_input.width, m_img_input.height), IPL_DEPTH_8U, 1); // ”§F’Šo—p
-		m_temp_buff = cvCreateImage(cvSize(m_img_input.width, m_img_input.height), IPL_DEPTH_8U, 1); // ˆêŽž•Û‘¶—p
-		m_label_buff = cvCreateImage(cvSize(m_img_input.width, m_img_input.height), IPL_DEPTH_16S, 1); // ƒ‰ƒxƒ‹Œ‹‰Ê•Û‘¶—p
-		m_output_buff = cvCreateImage(cvSize(m_img_input.width, m_img_input.height), IPL_DEPTH_8U, 3); // o—Í—p
+		m_image_buff = cvCreateImage(cvSize(m_img_input.width, m_img_input.height), IPL_DEPTH_8U, 3); // 入力Image
+		m_hsv_buff = cvCreateImage(cvSize(m_img_input.width, m_img_input.height), IPL_DEPTH_8U, 3); // HSV用
+		m_convexHull_buff = cvCreateImage(cvSize(m_img_input.width, m_img_input.height), IPL_DEPTH_8U, 3); // ConvexHull用
+		m_skin_buff = cvCreateImage(cvSize(m_img_input.width, m_img_input.height), IPL_DEPTH_8U, 1); // 肌色抽出用
+		m_temp_buff = cvCreateImage(cvSize(m_img_input.width, m_img_input.height), IPL_DEPTH_8U, 1); // 一時保存用
+		m_label_buff = cvCreateImage(cvSize(m_img_input.width, m_img_input.height), IPL_DEPTH_16S, 1); // ラベル結果保存用
+		m_output_buff = cvCreateImage(cvSize(m_img_input.width, m_img_input.height), IPL_DEPTH_8U, 3); // 出力用
 		
-		//InPort‚̉f‘œ‚̎擾
+		//InPortの映像の取得
 		memcpy(m_image_buff->imageData,(void *)&(m_img_input.pixels[0]),m_img_input.pixels.length());
 		
-		// ”§F‚𒊏o‚·‚éB
-		extractSkinColor( m_image_buff, m_hsv_buff, m_skin_buff);
+		// 肌色を抽出する。
+		extractSkinColor();
 		
-		// Œ‡‘¹—̈æ‚ð•âŠÔ‚·‚é
-		interpolate( m_skin_buff, m_temp_buff );
+		// 欠損領域を補間する
+		interpolate();
 		
-		//	ƒ‰ƒxƒŠƒ“ƒO‚ðs‚¤
+		//	ラベリングを行う
 		Label *labeling = createLabeling();
 		exec( labeling, m_skin_buff, m_label_buff, true, IGNORE_SIZE );
 
 		if(getNumOfResultRegions( labeling ) > 0 ) {
-			//	IGNORE_SIZE‚æ‚è‚à‘å‚«‚ȗ̈悪‚ ‚Á‚½ê‡
-			int handarea;		//	Žè—̈æ‚̖ʐÏ
-			int hullarea;		//	ConvexHull“à‚̖ʐÏ
-			int hullcount;		//	ConvexHull‚Ì’¸“_‚̐”
-			CvPoint *handpoint;	//	Žè—̈æ“à‚Ì“_‚̍À•W”z—ñ
-			int *hull;			//	ConvexHull‚Ì’¸“_‚Ìhandpoint‚É‚¨‚¯‚éindex”ԍ†
-			CvMat pointMatrix;	//	Žè—̈æ—ps—ñ
-			CvMat hullMatrix;	//	ConvexHull—ps—ñ
+			//	IGNORE_SIZEよりも大きな領域があった場合
+			int handarea;		//	手領域の面積
+			int hullarea;		//	ConvexHull内の面積
+			int hullcount;		//	ConvexHullの頂点の数
+			CvPoint *handpoint;	//	手領域内の点の座標配列
+			int *hull;			//	ConvexHullの頂点のhandpointにおけるindex番号
+			CvMat pointMatrix;	//	手領域用行列
+			CvMat hullMatrix;	//	ConvexHull用行列
 
-			//	Å‘å—̈æ(Žè—̈æ)‚Ì’Šo‚ðs‚¤
-			handarea = pickupMaxArea( m_skin_buff, m_label_buff, m_convexHull_buff );
+			//	最大領域(手領域)の抽出を行う
+			handarea = pickupMaxArea();
 
-			//	ConvexHull‚𐶐¬‚·‚é
-			createConvexHull( m_skin_buff, handarea, &handpoint, &hull, &pointMatrix, &hullMatrix );
+			//	ConvexHullを生成する
+			createConvexHull( handarea, &handpoint, &hull, &pointMatrix, &hullMatrix );
 			
 			hullcount = hullMatrix.cols;
 
-			//	ConvexHull‚ð•`‰æ‚·‚é
-			drawConvexHull( m_convexHull_buff, handpoint, hull, hullcount );
+			//	ConvexHullを描画する
+			drawConvexHull( handpoint, hull, hullcount );
 
-			//	ConvexHull“à‚Ì–ÊÏ‚ð‹‚ß‚é
-			hullarea = calcConvexHullArea( m_convexHull_buff, handpoint,hull, hullcount );
+			//	ConvexHull内の面積を求める
+			hullarea = calcConvexHullArea( handpoint,hull, hullcount );
 
-			//	ƒWƒƒƒ“ƒPƒ“‚Ì”»’è‚ðs‚¤
+			//	ジャンケンの判定を行う
 			decide( handarea, hullarea );
 
-			//	ƒƒ‚ƒŠ‚ð‰ð•ú‚·‚é
+			//	メモリを解放する
 			free( handpoint );
 			free( hull );
-			
+
 		} else {
 		
-			//	‰æ‘œ‚ð‰Šú‰»‚·‚é
+			//	画像を初期化する
 			cvSetZero( m_convexHull_buff );
 
 		}
@@ -441,23 +269,23 @@
 		releaseLabeling( labeling );
 
 		if ( m_skin_buff->origin == 0 ) {
-			//@¶ã‚ªŒ´“_‚̏ꍇ
+			// 左上が原点の場合
 			cvFlip( m_skin_buff, m_skin_buff, 0 );
 		}
 		if ( m_convexHull_buff->origin == 0 ) {
-			//@¶ã‚ªŒ´“_‚̏ꍇ
+			// 左上が原点の場合
 			cvFlip( m_convexHull_buff, m_convexHull_buff, 0 );
 		}
 
-		// ‰æ‘œƒf[ƒ^‚̃TƒCƒYŽæ“¾
+		// 画像データのサイズ取得
 		double len = (m_output_buff->nChannels * m_output_buff->width * m_output_buff->height);
 		
 		m_img_output.pixels.length(len);
 
-		// ŠY“–‚̃Cƒ[ƒW‚ðMemCopy‚·‚é
+		// 該当のイメージをMemCopyする
 		memcpy((void *)&(m_img_output.pixels[0]), m_convexHull_buff->imageData, len);
 		
-		// ”½“]‚µ‚½‰æ‘œƒf[ƒ^‚ðOutPort‚©‚ço—Í‚·‚éB
+		// 反転した画像データをOutPortから出力する。
 		m_img_output.width = m_image_buff->width;
 		m_img_output.height = m_image_buff->height;
 
@@ -511,8 +339,220 @@
 }
 */
 
+//
+//	肌色を抽出する
+//
+void RockPaperScissors::extractSkinColor( void )
+{
+	CvScalar color;		//	HSV表色系で表した色
+	unsigned char h;	//	H成分
+	unsigned char s;	//	S成分
+	unsigned char v;	//	V成分
+	
+	//	BGRからHSVに変換する
+	
+	cvCvtColor( m_image_buff, m_hsv_buff, CV_BGR2HSV );
+	
+	//肌色抽出
+	for( int x = 0; x < m_skin_buff->width; x++ ) {
+		for( int y = 0 ; y < m_skin_buff->height; y++ ) {
 
+			color = cvGet2D( m_hsv_buff, y, x );
+			h = color.val[0];
+			s = color.val[1];
+			v = color.val[2];
 
+			if( h <= HMAX && h >= HMIN &&
+				s <= SMAX && s >= SMIN &&
+					v <= VMAX && v >= VMIN ) {
+				//	肌色の場合
+				cvSetReal2D( m_skin_buff, y, x, 255 );
+			} else {
+				cvSetReal2D( m_skin_buff, y, x, 0 );
+			}
+		}
+
+	}
+}
+
+//
+//	欠損領域を補間する
+//
+void RockPaperScissors::interpolate( void )
+{
+	//膨張をITERATIONS回行う
+	cvDilate( m_skin_buff, m_temp_buff, NULL, m_iterations );
+
+	//収縮をITERATIONS回行う
+	cvErode( m_temp_buff, m_skin_buff, NULL, m_iterations );
+}
+
+//
+//	最大領域(手領域)の抽出を行う
+//
+//	戻り値:
+//		手領域の面積
+//
+int RockPaperScissors::pickupMaxArea( void )
+{
+	int handarea = 0;	//	手領域の面積
+
+	for(int x = 0; x < m_skin_buff->width; x++ ) {
+		for( int y=0; y < m_skin_buff->height; y++ ) {
+			if( cvGetReal2D( m_label_buff, y, x ) == 1 ) {
+				//	最大領域だった場合
+				handarea++;
+				cvSet2D( m_convexHull_buff, y, x, CV_RGB( 255, 255, 255 ) );
+			} else {
+				cvSetReal2D( m_skin_buff, y, x, 0 );
+				cvSet2D( m_convexHull_buff, y, x, CV_RGB( 0, 0, 0 ) );
+			}
+		}
+	}
+	return handarea;
+}
+
+//
+//	ConvexHullを生成する
+//
+//	引数:
+//		handarea    : 手領域の面積(点の数)
+//		handpoint   : 手領域内の点の座標配列へのポインタ
+//		hull        : ConvexHullの頂点のhandpointにおけるindex番号へのポインタ
+//		pointMatrix : 手領域用行列へのポインタ
+//		hullMatrix  : ConvexHull用行列へのポインタ
+//
+void RockPaperScissors::createConvexHull( int handarea, CvPoint **handpoint, int **hull,
+					  CvMat *pointMatrix, CvMat *hullMatrix )
+{
+	int i=0;
+
+	//	ConvexHullを計算するために必要な行列を生成する
+	*handpoint=( CvPoint * )malloc( sizeof( CvPoint ) * handarea );
+	*hull = ( int * )malloc( sizeof( int ) * handarea );
+	*pointMatrix = cvMat( 1, handarea, CV_32SC2, *handpoint );
+	*hullMatrix = cvMat( 1, handarea, CV_32SC1, *hull );
+
+	for( int x = 0; x < m_skin_buff->width; x++ ) {
+		for(  int y = 0; y < m_skin_buff->height; y++ ) {
+			if( cvGetReal2D( m_skin_buff, y, x ) == 255 ) {
+				( *handpoint )[i].x = x;
+				( *handpoint )[i].y = y;
+				i++;
+			}
+		}
+	}
+
+	//	ConvexHullを生成する
+	cvConvexHull2( pointMatrix, hullMatrix, CV_CLOCKWISE, 0 );
+}
+
+//
+//	ConvexHullを描画する
+//
+//	引数:
+//		handpoint       : 手領域内の点の座標配列
+//		hull            : ConvexHullの頂点のhandpointにおけるindex番号
+//		hullcount       : ConvexHullの頂点の数
+//
+void RockPaperScissors::drawConvexHull( CvPoint *handpoint, int *hull, int hullcount )
+{
+	CvPoint pt0 = handpoint[hull[hullcount-1]];
+	for( int i = 0; i < hullcount; i++ ) {
+		CvPoint pt = handpoint[hull[i]];
+		cvLine( m_convexHull_buff, pt0, pt, CV_RGB( 0, 255, 0 ) );
+		pt0 = pt;
+	}
+}
+
+//
+//	ConvexHull内の面積を求める
+//
+//	引数:
+//		handpoint       : 手領域内の点の座標配列
+//		hull            : ConvexHullの頂点のhandpointにおけるindex番号
+//		hullcount       : ConvexHullの頂点の数  
+//
+//	戻り値:
+//		ConvexHull内の面積
+//
+int RockPaperScissors::calcConvexHullArea( CvPoint *handpoint, int *hull, int hullcount )
+{
+	//	ConvexHullの頂点からなる行列を生成
+	CvPoint *hullpoint = ( CvPoint * )malloc( sizeof( CvPoint ) * hullcount );
+
+	CvMat hMatrix = cvMat( 1, hullcount, CV_32SC2, hullpoint );
+	for( int i = 0; i < hullcount; i++ ) {
+		hullpoint[i]=handpoint[hull[i]];
+	}
+
+	//	ConvexHull内の点の数を数える
+	int hullarea = 0;
+	for( int x = 0; x < m_convexHull_buff->width; x++ ) {
+		for( int y = 0;y < m_convexHull_buff->height; y++ ) {
+
+			if( cvPointPolygonTest( &hMatrix, cvPoint2D32f( x, y ), 0 ) > 0) {
+				hullarea++;
+			}
+		}
+	}
+
+	free( hullpoint );
+	return hullarea;
+}
+
+
+//
+//	ジャンケンの判定を行う
+//
+//	引数:
+//		handarea : 手領域の面積
+//		hullarea : ConvexHull内の面積
+//
+void RockPaperScissors::decide( int handarea, int hullarea )
+{
+	double ratio;	//	ConvexHull内の面積に対する手領域の面積の割合
+	string judge = "閾値外";
+	
+	ratio=handarea / ( double )hullarea;	
+
+	if( ratio >= m_rock_min && ratio <= m_rock_max ) {
+	  judge = "グー";
+	}
+	else if( ratio >= m_scissor_min && ratio <= m_scissor_max )
+	{
+    judge = "チョキ";
+	}
+	else if( ratio >= m_paper_min && ratio <= m_paper_max )
+	{
+    judge = "パー";
+	}
+	
+	if( m_out_mode == 1 )
+	{
+	  //前回とジャンケンの種類が異なる場合のみ出力する
+	  //ConvexHull領域は一定以上の大きさでないと、ジャンケンの判定は意味がない
+	  //ここでは暫定的に10000以上の領域に対してジャンケンを判定するものとする
+	  if( judge != "閾値外" && m_prev_judge != judge && hullarea >= 10000 )
+	  {
+	    //printf( "Ratio = %lf\n", ratio );
+	    printf( "Ratio = %lf  : 判定領域の大きさ = %d\n", ratio,  hullarea );
+      printf( "%s\n", judge.c_str() );
+      m_prev_judge = judge;
+
+      m_result.data = judge.c_str();
+      m_resultOut.write();
+    }
+  }
+  else
+  {
+    //すべての結果を出力する
+    printf( "Ratio = %lf  : 判定領域の大きさ = %d\n", ratio,  hullarea );
+    printf( "%s\n", judge.c_str() );
+  }
+}
+
+
 extern "C"
 {
  



More information about the openrtm-commit mailing list