package cz.vutbr.feec.utko.opencv.operators;

import static com.googlecode.javacv.cpp.opencv_core.*;
import static com.googlecode.javacv.cpp.opencv_highgui.*;

import com.rapidminer.operator.Operator;
import com.rapidminer.operator.OperatorDescription;
import com.rapidminer.operator.OperatorException;
import com.rapidminer.operator.ports.OutputPort;

import cz.vutbr.feec.utko.opencv.io.OpenCVIOObject;

public class ReadFromCamera extends Operator {
	private OutputPort outOpenCv = getOutputPorts().createPort("color image");
	
	public ReadFromCamera(OperatorDescription description) {
		super(description);
		getTransformer().addGenerationRule(outOpenCv, OpenCVIOObject.class);
	}
	
	@Override
	public void doWork() throws OperatorException {
		
		// TODO Funguje jen na poprve. Pri opetovnem spusteni procesu 
		// jiz nevraci spravne hodnoty
		
		CvCapture capture = cvCreateCameraCapture(0);
		IplImage img = cvQueryFrame(capture);
		outOpenCv.deliver(new OpenCVIOObject(img));
	}
	
}
