本文整理汇总了C++中ofVideoGrabber::getPixelsRef方法的典型用法代码示例。如果您正苦于以下问题:C++ ofVideoGrabber::getPixelsRef方法的具体用法?C++ ofVideoGrabber::getPixelsRef怎么用?C++ ofVideoGrabber::getPixelsRef使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ofVideoGrabber
的用法示例。
在下文中一共展示了ofVideoGrabber::getPixelsRef方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: update
void update()
{
// Update our little offset thingy.
offset += 0.01;
if (offset > 1)
{
offset = 0;
}
// Update our camera.
grabber.update();
// If the camera has a new frame to offer us ...
if (grabber.isFrameNew())
{
// Make a copy of our grabber pixels in the colorImage.
colorImage.setFromPixels(grabber.getPixelsRef());
// When we assign a color image to a grayscale image, it is converted automatically.
grayscaleImage = colorImage;
// If we set learnBackground to true using the keyboard, we'll take a snapshot of
// the background and use it to create a clean foreground image.
if (learnBackground == true)
{
// We assign the grayscaleImage to the grayscaleBackgroundImage.
grayscaleBackgroundImage = grayscaleImage;
// Now we set learnBakground so we won't set a background unless
// explicitly directed to with a keyboard command.
learnBackground = false;
}
// Create a difference image by comparing the background and the current grayscale images.
grayscaleAbsoluteDifference.absDiff(grayscaleBackgroundImage, grayscaleImage);
// Assign grayscaleAbsoluteDifference to the grayscaleBinary image.
grayscaleBinary = grayscaleAbsoluteDifference;
// Then threshold the grayscale image to create a binary image.
grayscaleBinary.threshold(threshold, invert);
// Find contours (blobs) that are between the size of 20 pixels and
// 1 / 3 * (width * height) of the camera. Also find holes.
contourFinder.findContours(grayscaleBinary, 100, (width * height) / 3.0, 10, true);
// Get the biggest blob and use it to draw.
if (contourFinder.nBlobs > 0)
{
holePositions.addVertex(contourFinder.blobs[0].boundingRect.getCenter());
}
else
{
holePositions.clear();
}
}
}
示例2: update
// Called every frame.
void update() {
// Update our camera.
grabber.update();
// If the camera has a new frame to offer us ...
if (grabber.isFrameNew())
{
// Get a reference (denoted by &) to the camera's pixels. Getting a
// reference means that we won't have to make a copy of all of the
// frame's pixels (since we only need one column anyway). This means our
// program requires less processing power.
//
// const prevents us from accidentally modifying the cameras's pixels.
const ofPixels& cameraPixels = grabber.getPixelsRef();
// Choose a slit location. In this case we'll collect slits from the
// column in the middle of the camera feed.
int slitPositionX = grabber.getWidth() / 2;
// Cycle through each pixel in the selected column and place that pixel
// at a position x = xPosition and y = to the same position as the
// oritinal.
for (int y = 0; y < grabber.getHeight(); y++)
{
// Get the pixel as a color at x / y from the grabber.
ofColor pixelFromGrabber = cameraPixels.getColor(slitPositionX, y);
// Set that pixel color to the x / y position in the output pixels.
pixels.setColor(xPosition, y, pixelFromGrabber);
}
// Increment our xPosition so next update we'll draw a colum shifted to
// the right by one pixel.
xPosition = xPosition + 1;
// If our xPosition is greater than or equal to the width of the display
// pixels, reset our x position to 0.
if (xPosition >= pixels.getWidth())
{
xPosition = 0;
}
}
}