本文整理汇总了C++中VideoBuffer::data方法的典型用法代码示例。如果您正苦于以下问题:C++ VideoBuffer::data方法的具体用法?C++ VideoBuffer::data怎么用?C++ VideoBuffer::data使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VideoBuffer
的用法示例。
在下文中一共展示了VideoBuffer::data方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: glGetIntegerv
void CaptureCallback::ContextData::readImage()
{
int width = _graphicsContext->getTraits()->width;
int height = _graphicsContext->getTraits()->height;
if (width!=_width || _height!=height)
{
_width = width;
_height = height;
}
if (_delegate)
{
VideoBuffer *buffer = _delegate->getVideoBuffer();
GLint internalFormat = GL_BGRA; // This is fine for iOS
#ifdef ANDROID // Depending in the platform / android version, the pixel format will change
glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT, &internalFormat);
if (internalFormat == GL_RGB)
internalFormat = GL_RGBA;
#endif
buffer->pixelFormat = internalFormat;
size_t bpp = buffer->bpp();
size_t bpr = buffer->bpr();
GLubyte *pixelBufferData = (GLubyte *)buffer->data();
glReadPixels(0, 0, width, height, internalFormat, GL_UNSIGNED_BYTE, pixelBufferData);
if (bpr != width*bpp){
// There is some padding expected in the buffer, let's move stuff around
for (int y = height-1; y > 0; --y){
memmove(pixelBufferData + y * bpr, pixelBufferData + y * width * bpp, width * bpp);
}
}
_delegate->didCaptureImage();
}
}
示例2: main
//.........这里部分代码省略.........
namedWindow("Vision",1);
//createTrackbar("Thresh Type", "Vision", &type, 4, NULL); // callback not needed
//createTrackbar("Min Value", "Vision", &defMin, 255, NULL); // callback not needed
//createTrackbar("Max Value", "Vision", &defMax, 255, NULL); // callback not needed
createTrackbar("Percent Tall", "Vision", &defTall, 20, NULL); // callback not needed
createTrackbar("Percent Narr", "Vision", &defNarr, 20, NULL); // callback not needed
} else {
table->PutNumber("Horizontal Percent Error", defTall);
table->PutNumber("Vertical Percent Error", defNarr);
}
for (int i = 0; i<10; i++)
start[i] = getmsofday(); // pre-load with 'now'
for (int i = 0; 1; i++) {
// Receive key-press updates, it is required if you want to output images,
// so the task takes a moment to update the display.
if (waitKey(1) > 0)
break;
string fileStream = "Mask"; // Default if no table present
if (table->IsConnected()) {
NetworkTable *StreamsTable = table->GetSubTable("File Streams");
if (StreamsTable && StreamsTable->ContainsKey("selected")) {
fileStream = StreamsTable->GetString("selected");
}
}
ShowMask = (fileStream == "Mask");
// Grab a frame from the vision API
VideoBuffer buffer = v.grabFrame();
// Put the frame into an OpenCV image matrix with a single color (gray scale)
Mat image(height, width, CV_8UC1, buffer.data(), false); // AKA 'Y'
Mat dst; // this will be a RGB version of the source image
#if defined(YOU_WANT_RGB_COLOR_INSTEAD_OF_GREYSCALE)
// There is more data after the gray scale (Y) that contains U&V
Mat cb(height/2, width/2, CV_8UC1, buffer.data()+(height*width), false); // 'U'
Mat cr(height/2, width/2, CV_8UC1, buffer.data()+(height*width)*5/4, false); // 'V'
// size up cb and cr to be same as y
Mat CB;
resize(cb,CB,cvSize(width,height));
Mat CR;
resize(cr,CR,cvSize(width,height));
// empty image same as full (gray scale) image, but 3 channels:
Mat ycbcr(height,width, CV_8UC3);
Mat in[] = {image, CB, CR};
int fromto[] = {0,0, 1,1, 2,2}; // YUV
// mash 3 channels from 2 matrix into a single 3 channel matrix:
mixChannels(in,3, &ycbcr,1, fromto,3);
// convert that 3 channel YUV matrix into 3 channel RGB (displayable)
cvtColor(ycbcr,image,CV_YCrCb2RGB);
if (ShowMask) {
dst = image.clone(); // make a copy, as we want dst to have the same RGB version
}
#else
// After calculates, we want to draw 'on' the image, showing our results
// graphically in some fashion -- that has to happen on a RGB
if (ShowMask) {