Skip to content

Instantly share code, notes, and snippets.

@Bernardstanislas
Created January 16, 2015 08:32
Show Gist options
  • Save Bernardstanislas/850a0198c8d1a2bde7be to your computer and use it in GitHub Desktop.
Save Bernardstanislas/850a0198c8d1a2bde7be to your computer and use it in GitHub Desktop.
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment