Example #1
0
void resetStreamCropping(openni::VideoStream& stream)
{
	if (!stream.isValid())
	{
		displayMessage("Stream does not exist!");
		return;
	}
	
	if (!stream.isCroppingSupported())
	{
		displayMessage("Stream does not support cropping!");
		return;
	}
	
	openni::Status nRetVal = stream.resetCropping();
	if (nRetVal != openni::STATUS_OK)
	{
		displayMessage("Failed to reset cropping: %s", xnGetStatusString(nRetVal));
		return;
	}
}
Example #2
0
void setStreamCropping(openni::VideoStream& stream, int originX, int originY, int width, int height)
{
	if (!stream.isValid())
	{
		displayMessage("Stream does not exist!");
		return;
	}
	
	if (!stream.isCroppingSupported())
	{
		displayMessage("Stream does not support cropping!");
		return;
	}
	
	openni::Status nRetVal = stream.setCropping(originX, originY, width, height);
	if (nRetVal != openni::STATUS_OK)
	{
		displayMessage("Failed to set cropping: %s", xnGetStatusString(nRetVal));
		return;
	}
}
Example #3
0
void drawCropStream(openni::VideoStream& stream, IntRect location, IntRect selection, int dividedBy)
{
	if (!stream.isCroppingSupported())
	{
		return;
	}

	openni::VideoMode Mode = stream.getVideoMode();

	// check if entire selection is in location
	if (selection.uLeft >= location.uLeft &&
		selection.uRight <= location.uRight &&
		selection.uBottom >= location.uBottom &&
		selection.uTop <= location.uTop)
	{
		IntRect cropRect;
		cropRect.uBottom = Mode.getResolutionY() * (selection.uBottom - location.uBottom) / (location.uTop - location.uBottom);
		cropRect.uTop    = Mode.getResolutionY() * (selection.uTop - location.uBottom)    / (location.uTop - location.uBottom);
		cropRect.uLeft   = Mode.getResolutionX()  * (selection.uLeft - location.uLeft)     / (location.uRight - location.uLeft);
		cropRect.uRight  = Mode.getResolutionX()  * (selection.uRight - location.uLeft)    / (location.uRight - location.uLeft);

		int originX, originY, width, height;

		originX    = cropRect.uLeft;
		originY    = cropRect.uBottom;
		width  = cropRect.uRight - cropRect.uLeft;
		height = cropRect.uTop   - cropRect.uBottom;

		if ((originX % dividedBy) != 0)
			originX -= (originX % dividedBy);
		if ((width % dividedBy) != 0)
			width += dividedBy - (width % dividedBy);

		setStreamCropping(stream, originX, originY, width, height);
	}
}