<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-
import time
from component import Component
from IO import O, ImageData
from SimpleCV import Color
import cv2

class Cropper(Component):

	attr_description = Component.attr_description + "output:O:output writer,x:int:top left point's abscisse of cropping rectangle,\
		y:int:top left point's ordonate of cropping rectangle,width:int:width of cropping rectangle,\
		height:int:height of cropping rectangle"

	description = "Component for cropping images. It takes as input a list of images and returns the list of cropped images"

	def __init__(self):
		Component.__init__(self)
		self.output = O()
		self.x = 0
		self.y = 0
		self.width = 100
		self.height = 100

	def process(self):

		if not self.executed and (self.parent is not None):
			self.executeParent()

			self.images = self.parent.images
			for im in self.images:
				im.image = im.image.crop(self.x,self.y,self.width,self.height)
			
			self.output.write(self.images,'../../test/cropped/',self.id)

			self.executed = True

class GrayScale(Component):

	attr_description = Component.attr_description + "output:O:output writer,degree:int:output images darkness"

	description = "Component for turning the images into gray scale. It takes as input a list of images and returns the list of gray images"

	def __init__(self):
		Component.__init__(self)
		self.output = O()
		self.degree = 1

	def process(self):

		if not self.executed and (self.parent is not None):
			self.executeParent()

			self.images = self.parent.images

			for im in self.images:
				(red, green, blue) = im.image.splitChannels(False)
				im.image = (red.toGray() + green.toGray() + blue.toGray()) / self.degree

			self.executed = True
			
			self.output.write(self.images,'../../test/binarized/',self.id)

class ChromaKey(Component):

	def __init__(self):
		Component.__init__(self)
		self.green_screen = ImageData("../test/greenScreen.jpg")
		self.green_screen.load()
		self.background = ImageData("../test/landscape.jpg")
		self.background.load()
		self.green_screen.image = self.green_screen.image.scale(self.background.image.width, self.background.image.height)

	def process(self):

		if not self.executed and (self.parent is not None):
			self.executeParent()

			mask = self.green_screen.image.hueDistance(color=Color.GREEN).binarize()
			
			result = (self.green_screen.image - mask) + (self.background.image - mask.invert())
			result.show()
			time.sleep(10)

class FacesDetector(Component):

	def __init__(self):
		Component.__init__(self)
		self.image = ImageData("../../test/people.jpg")
		self.cascade = cv2.CascadeClassifier('../../XML/haarcascade_frontalface_default.xml')
		self.image.load()
		self.output = O()

	def process(self):

		if not self.executed and self.parent is not None:
			self.executeParent()

			img = cv2.imread("../../test/people.jpg")
			gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)<commit_msg>chromakey reorganization<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-
import time
from component import Component
from IO import O, ImageData
from SimpleCV import Color
import cv2

class Cropper(Component):

	attr_description = Component.attr_description + "output:O:output writer,x:int:top left point's abscisse of cropping rectangle,\
		y:int:top left point's ordonate of cropping rectangle,width:int:width of cropping rectangle,\
		height:int:height of cropping rectangle"

	description = "Component for cropping images. It takes as input a list of images and returns the list of cropped images"

	def __init__(self):
		Component.__init__(self)
		self.output = O()
		self.x = 0
		self.y = 0
		self.width = 100
		self.height = 100

	def process(self):

		if not self.executed and (self.parent is not None):
			self.executeParent()

			self.images = self.parent.images
			for im in self.images:
				im.image = im.image.crop(self.x,self.y,self.width,self.height)
			
			self.output.write(self.images,'../../test/cropped/',self.id)

			self.executed = True

class GrayScale(Component):

	attr_description = Component.attr_description + "output:O:output writer,degree:int:output images darkness"

	description = "Component for turning the images into gray scale. It takes as input a list of images and returns the list of gray images"

	def __init__(self):
		Component.__init__(self)
		self.output = O()
		self.degree = 1

	def process(self):

		if not self.executed and (self.parent is not None):
			self.executeParent()

			self.images = self.parent.images

			for im in self.images:
				(red, green, blue) = im.image.splitChannels(False)
				im.image = (red.toGray() + green.toGray() + blue.toGray()) / self.degree

			self.executed = True
			
			self.output.write(self.images,'../../test/binarized/',self.id)

class ChromaKey(Component):

	description = "Composes all the images in input1 with the background image defined in input2"
	attr_description = Component.attr_description + "background:ImageData:the image applied as background,parent2:component:second parent"

	def __init__(self):
		Component.__init__(self)
		self.background
		self.parent2 = None

	def setParent2(self, parent):
		self.parent2 = parent
		if parent is None :
			self.executed = False

	def delParent2(self):
		self.parent2 = None
		self.executed = False

	def process(self):

		if not self.executed and self.parent is not None:
			self.executeParent()

			for i in self.images:
				background = self.background.image.scale(i.image.width, i.image.height)
				mask = background.hueDistance(color=Color.GREEN).binarize()
				
				result = (background - mask) + (background - mask.invert())

class FacesDetector(Component):

	def __init__(self):
		Component.__init__(self)
		self.image = ImageData("../../test/people.jpg")
		self.cascade = cv2.CascadeClassifier('../../XML/haarcascade_frontalface_default.xml')
		self.image.load()
		self.output = O()

	def process(self):

		if not self.executed and self.parent is not None:
			self.executeParent()

			img = cv2.imread("../../test/people.jpg")
			gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
{'fraction_non_alphanumeric': 0.12308199967002145, 'fraction_numerical': 0.006929549579277347, 'mean_word_length': 3.8847703464947623, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2735895', 'n_tokens_mistral': 2158, 'n_tokens_neox': 1898, 'n_words': 502}