Beispiel #1
0
// Blend pixel old color with a new color
inline void blendAndSetPixel(ColorImage &img, int x, int y, ColorPixel color, float alpha) {
	if (x >= 0 && x < img.cols && y >= 0 && y < img.rows) {
		const int blendRed = (color.red * alpha) + ((1.0f - alpha) * img.data[y][x].red);
		const int blendGreen = (color.green * alpha) + ((1.0f - alpha) * img.data[y][x].green);
		const int blendBlue = (color.blue * alpha) + ((1.0f - alpha) * img.data[y][x].blue);
		img.data[y][x] = ColorPixel(blendRed, blendGreen, blendBlue);
	}
}
Beispiel #2
0
ColorDetector::ColorDetector(AlgoPropertySystem* system,
							 QObject* parent)
	: AlgoPropertyManager(tr("Color Detector"), system, parent)
	, m_targetColor(tr("Target Color"), ColorPixel(0,255,0))
	, m_threshold(tr("Threshold"), 100, 0, 1000)
{
	addProperty(m_targetColor);
	addProperty(m_threshold);
}
void MapColorToDepth(const DataTypes::DepthImage& depthImage, const DataTypes::ColorImage& colorImage, DataTypes::ColorImage& alignedColorImage)
{
	

	// Get of x, y coordinates for color in depth space
    // This will allow us to later compensate for the differences in location, angle, etc between the depth and color cameras
    sensor->NuiImageGetColorPixelCoordinateFrameFromDepthPixelFrameAtResolution(
        NUI_IMAGE_RESOLUTION_640x480,
        NUI_IMAGE_RESOLUTION_640x480,
        640*480,
        depthData,
        640*480*2,
        colorCoordinates
        );

	const long colorToDepthDivisor = COLOR_RES_X / DEPTH_RES_X;

	// loop over each row and column of the color
	for (long y = 0; y < COLOR_RES_Y; ++y)
    {
        for (long x = 0; x < COLOR_RES_X; ++x)
        {
            // calculate index into depth array
            int depthIndex = x/colorToDepthDivisor + y/colorToDepthDivisor * DEPTH_RES_X;

            // retrieve the depth to color mapping for the current depth pixel
            LONG colorInDepthX = colorCoordinates[depthIndex * 2];
            LONG colorInDepthY = colorCoordinates[depthIndex * 2 + 1];

            // make sure the depth pixel maps to a valid point in color space
            if ( colorInDepthX >= 0 && colorInDepthX < COLOR_RES_X && colorInDepthY >= 0 && colorInDepthY < COLOR_RES_Y )
            {
                // set source for copy to the color pixel
				alignedColorImage.data[y][x] = colorImage.data[colorInDepthY][colorInDepthX];
            }
            else
            {
                alignedColorImage.data[y][x] = ColorPixel(ColorPixel::Black);
            }

        }
    }
	
	alignedColorImage.rows = colorImage.rows;
	alignedColorImage.cols = colorImage.cols;

	return;
}
//---------------------------------------------------------------------------
// Entry Point
//---------------------------------------------------------------------------
int main(int argc, char* argv[])
{
	// Set up the KinectTable session parameters
	SessionParameters params;
	params.dataParams.colorImageEnable = true;
	params.dataParams.depthImageEnable = true;
	params.dataParams.validityImageEnable = false;
	params.dataParams.testImageEnable = showDebug;
	params.dataParams.handsEnable = true;

	// Initialize KinectTable as local session
	int ret = InitLocalSession(params);
	if(ret != 0) {
		return -1;
	}	

	// Set up the initialization parameters for viewing
	static View::InitParams initParams;
	initParams.initFunc = Init;
	initParams.deInitFunc = DeInit;
	initParams.idleFunc = NULL;
	initParams.displayFunc = Display;
	initParams.keyboardFunc = Keyboard;
	initParams.specialInputFunc = SpecialInput;
	initParams.resizeFunc = NULL;
	
	// Initialize the viewing
	View::Init(initParams);

	// build a depth lookup table
	raw2depth();

	// Load effect texture images
	if(!loadTattoos())
		return 0;

	//
	// Set up effects.
	// Note how to change tweakable parameters for each effect - look at Tint for example.
	//

	// Background removal
	viz.getEffect(KinectViz::kBackgroundRemover).enabled = false;

	// Skeleton
	viz.getEffect(KinectViz::kSkeleton).enabled = false;
	viz.getEffect(KinectViz::kSkeleton).minHeight = 0;
	viz.getEffect(KinectViz::kSkeleton).maxHeight = 1000;

	// Rainbow
	viz.getEffect(KinectViz::kRainbow).enabled = false;
	viz.getEffect(KinectViz::kRainbow).minHeight = 0;
	viz.getEffect(KinectViz::kRainbow).maxHeight = 1000;

	// Outline
	viz.getEffect(KinectViz::kOutline).enabled = false;
	viz.getEffect(KinectViz::kOutline).minHeight = 0;
	viz.getEffect(KinectViz::kOutline).maxHeight = 1000;

	// Pointer circle
	viz.getEffect(KinectViz::kPointerCircle).enabled = false;
	viz.getEffect(KinectViz::kPointerCircle).minHeight = 0;
	viz.getEffect(KinectViz::kPointerCircle).maxHeight = 1000;

	// Tint
	viz.getEffect(KinectViz::kTint).enabled = false;
	((KinectViz::Tint&)(viz.getEffect(KinectViz::kTint))).handColors[0] = ColorPixel(255,100,100);
	((KinectViz::Tint&)(viz.getEffect(KinectViz::kTint))).handColors[1] = ColorPixel(100,255,100);
	((KinectViz::Tint&)(viz.getEffect(KinectViz::kTint))).handColors[2] = ColorPixel(100,100,255);
	viz.getEffect(KinectViz::kTint).minHeight = 0;
	viz.getEffect(KinectViz::kTint).maxHeight = 1000;

	// Motion blur
	viz.getEffect(KinectViz::kMotionBlur).enabled = false;
	viz.getEffect(KinectViz::kMotionBlur).minHeight = 0;
	viz.getEffect(KinectViz::kMotionBlur).maxHeight = 1000;

	// Traces
	viz.getEffect(KinectViz::kTraces).enabled = false;
	viz.getEffect(KinectViz::kTraces).minHeight = 0;
	viz.getEffect(KinectViz::kTraces).maxHeight = 1000;

	// Shadows
	viz.getEffect(KinectViz::kShadow).enabled = false;
	viz.getEffect(KinectViz::kShadow).minHeight = 0;
	viz.getEffect(KinectViz::kShadow).maxHeight = 1000;

	// Transparency
	viz.getEffect(KinectViz::kTransparency).enabled = false;
	viz.getEffect(KinectViz::kTransparency).minHeight = 0;
	viz.getEffect(KinectViz::kTransparency).maxHeight = 1000;

	// Tattoos
	viz.getEffect(KinectViz::kTattoo).enabled = false;
	viz.getEffect(KinectViz::kTattoo).minHeight = 0;
	viz.getEffect(KinectViz::kTattoo).maxHeight = 1000;

	// Start the application
	View::StartLoop();

	return 0;
}
bool CreateGraphicalImage(KinectData& data, ColorImage& testImage)
{
	// Use color image as background
	if(data.available.colorImageEnable)
	{
		// Copy over color image
		data.colorImage.CopyTo(testImage);
	}


	// Create table image
	static BinaryImage tableBlob;
	data.table.CreateTableBlob(tableBlob);
	
	
	// Draw arms on image
	if(data.available.handsEnable)
	{	
		// Draw boundaries around arms
		static const ColorPixel armColors[] = { ColorPixel(ColorPixel::Black), ColorPixel(ColorPixel::Red), ColorPixel(ColorPixel::Green), ColorPixel(ColorPixel::Blue) };
		for(int i=0; i<data.hands.size(); i++)
		{
			const std::vector<Point2Di>& boundary = data.hands[i].boundary;

			if(data.hands[i].id + 1 < sizeof(armColors) / sizeof(ColorPixel));
			{
				for(int j=0; j<boundary.size(); j++)
				{
					const Point2Di& point = boundary[j];
					testImage.data[point.y][point.x] = armColors[data.hands[i].id + 1];
				}
			}
		}
		
		
		// Draw the finger tips
		for(int i=0; i<data.hands.size(); i++)
		{
			const Hand& hand = data.hands[i];
			Util::Drawing::DrawPoints(testImage, hand.fingerTips, ColorPixel(ColorPixel::Green), 3);
		}

		// Draw the finger bases
		/*for(int i=0; i<data.hands.size(); i++)
		{
			const Hand& hand = data.hands[i];
			Util::Drawing::DrawPoints(testImage, hand.fingerBases, ColorPixel(ColorPixel::Red), 3);
		}*/

		// Draw the arm base
		for(int i=0; i<data.hands.size(); i++)
		{
			const Hand& hand = data.hands[i];
			if(hand.armBase.x != -1 && hand.armBase.y != -1)
				Util::Drawing::DrawPoints(testImage, hand.armBase, ColorPixel(ColorPixel::Blue), 5);
		}

		
		// Draw the hand palm
		for(int i=0; i<data.hands.size(); i++)
		{
			const Hand& hand = data.hands[i];
			if(hand.palmCenter.x != -1 && hand.palmCenter.y != -1)
				Util::Drawing::DrawPoints(testImage, hand.palmCenter, ColorPixel(255, 0, 255), 5);
		}

		// Centroid
		for(int i=0; i<data.hands.size(); i++)
		{
			const Hand& hand = data.hands[i];
			if(hand.centroid.x != -1 && hand.centroid.y != -1)
				Util::Drawing::DrawPoints(testImage, hand.centroid, ColorPixel(255, 0, 0), 3);
		}
		
	}
	

	return true;
}
Beispiel #6
0
//virtual
void ColorDetector::exchange(WSettingExchanger& e)
{
	e.handle(m_targetColor, "targetColor", ColorPixel(0,255,0));
	e.handle(m_threshold, "threshold", 1000);
}