Bernardstanislas
1/16/2015 - 8:32 AM

TP1 de vision par ordinateur

TP1 de vision par ordinateur

import numpy as np
import cv2
from math import *
import os

databasePath = "db"
outputPath = "output"


def readImage(imagePath):
	return cv2.imread(databasePath + "/" + imagePath)

def recognizeSkinFromBGR(image):
	image_dimensions = image.shape[0:2]

	for x in range(image_dimensions[0]):
		for y in range(image_dimensions[1]):
			B = image.item(x,y,0)
			G = image.item(x,y,1)
			R = image.item(x,y,2)
			if not(R > 95 and G > 40 and B > 20 and (max(R, G, B) - min(R, G, B)) > 15 and abs(R - G) > 15 and R > G and R > B):
				image.itemset((x,y,0),255)
				image.itemset((x,y,1),255)
				image.itemset((x,y,2),255)
	return image


for imagePath in os.listdir(databasePath):
	print("Processing " + imagePath)
	image = readImage(imagePath)
	imageProcessed = recognizeSkinFromBGR(image)
	cv2.imwrite(outputPath + "/" + imagePath, imageProcessed)