コード例 #1
0
ファイル: processUnit.py プロジェクト: Schabernack/moodmeter
	def applyModelToImage(self,img,model,point):
		img_hsv = cv.CreateMat(img.height, img.width, cv.CV_8UC3)
		img_out = cv.CreateMat(img.height, img.width, cv.CV_8UC1)
		img_bin = cv.CreateMat(img.height, img.width, cv.CV_8UC1)
		img_ero = cv.CreateMat(img.height, img.width, cv.CV_8UC1)
		img_fill = cv.CreateMat(img.height, img.width, cv.CV_8UC1)
		img_smooth = cv.CreateMat(img.height, img.width, cv.CV_8UC1)

		cv.CvtColor(img,img_hsv,cv.CV_BGR2HSV)
		Logger.addImage(img_hsv, "img_hsv")
		pv.addColor(img_hsv,"hsv")
		
		h_plane=cv.CreateMat(img.height, img.width, cv.CV_8UC1)
		s_plane=cv.CreateMat(img.height, img.width, cv.CV_8UC1)
		
		cv.Split(img_hsv, h_plane, s_plane, None, None)
		planes = [h_plane, s_plane]

		cv.CalcBackProject([cv.GetImage(i) for i in planes],img_out,model)
				
		cv.Threshold(img_out, img_bin, 10, 255.0 , cv.CV_THRESH_BINARY)
		Logger.addImage(img_bin, "img_binary")
		pv.addBinary(img_bin,"binary")
		cv.Erode(img_bin,img_ero,iterations=2)
		Logger.addImage(img_ero, "img_eroded")

		cv.Smooth(img_ero,img_smooth,smoothtype=cv.CV_MEDIAN,param1=7)
		Logger.addImage(img_smooth, "img_median")
		pv.addBinary(img_smooth,"median")

		return img_smooth
コード例 #2
0
ファイル: processUnit.py プロジェクト: Schabernack/moodmeter
	def fillHand(self,img,point):
		img_tmp = cv.CreateMat(img.height, img.width, cv.CV_8UC1)
		img_fill = cv.CreateMat(img.height, img.width, cv.CV_8UC1)
		kernell=cv.CreateStructuringElementEx(7,7,3,3, cv.CV_SHAPE_RECT)
	 
		img_open = cv.CreateMat(img.height, img.width, cv.CV_8UC1)
		cv.MorphologyEx(img,img_open, img_tmp, kernell, cv.CV_MOP_CLOSE, 2 )
		
		Logger.addImage(img_open, "img_opened")
		pv.addBinary(img_open,"opened")

		cv.Copy(img_open,img_fill)
				
		cv.FloodFill(img_fill,point,(120))
		Logger.addImage(img_fill, "img_filled")

		cv.Threshold(img_fill, img_fill, 130, 255.0 , cv.CV_THRESH_TOZERO_INV)
		cv.Threshold(img_fill, img_fill, 100, 255.0 , cv.CV_THRESH_BINARY)
		
		return img_fill