本文整理汇总了C++中ofImage::getPixelsRef方法的典型用法代码示例。如果您正苦于以下问题:C++ ofImage::getPixelsRef方法的具体用法?C++ ofImage::getPixelsRef怎么用?C++ ofImage::getPixelsRef使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ofImage
的用法示例。
在下文中一共展示了ofImage::getPixelsRef方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: process
void testApp::process(ofFbo & fbo, ofImage & image, string name){
fbo.begin();
ofClear(0);
shader.begin();
shader.setUniformTexture("tex", cam.getTextureReference(), 0 );
shader.setUniform2f("texSize", cam.getWidth(), cam.getHeight());
shader.setUniform2f("size", fbo.getWidth(), fbo.getHeight());
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex3f(0, 0, 0);
glTexCoord2f(fbo.getWidth(), 0);
glVertex3f(fbo.getWidth(), 0, 0);
glTexCoord2f(fbo.getWidth(), fbo.getHeight());
glVertex3f(fbo.getWidth(), fbo.getHeight(), 0);
glTexCoord2f(0,fbo.getHeight());
glVertex3f(0,fbo.getHeight(), 0);
glEnd();
shader.end();
fbo.end();
TIME_SAMPLE_START(name);
fbo.readToPixels(image.getPixelsRef());
//image.update();
TIME_SAMPLE_STOP(name);
//image.draw(0, 0);
}
示例2: normalizeImage
void testApp::normalizeImage(ofImage& img, ofImage& normalized) {
srcTracker.update(toCv(img));
if(srcTracker.getFound()) {
drawNormalized(srcTracker, img, srcNormalized);
normalized.allocate(normalizedWidth, normalizedHeight, OF_IMAGE_COLOR);
srcNormalized.readToPixels(normalized.getPixelsRef());
normalized.update();
} else {
ofLogWarning() << "couldn't find the face" << endl;
}
}
示例3: ofMap
void ofxDepthImageCompressor::convertTo8BitImage(unsigned short* buf, ofImage& image){
int nearPlane = 500;
int farPlane = 7000;
unsigned char* pix = image.getPixels();
int stride = image.getPixelsRef().getNumChannels();
for(int i = 0; i < 640*480; i++){
//ofMap(buf[i], nearPlane, farPlane, 255, 0, true);
unsigned char value = buf[i] == 0 ? 0 : 255 - (255 * (buf[i] - nearPlane) ) / farPlane;// + ofMap(buf[i], nearPlane, farPlane, 255, 0, true);
for(int c = 0; c < stride; c++){
pix[i*stride+c] = value;
}
}
image.update();
}
示例4: faceColorToTexture
void faceColorToTexture(ofMesh& mesh, ofImage& image)
{
vector<ofFloatColor> &color = mesh.getColors();
int num_face = color.size() / 3;
int tex_size = ofNextPow2(ceil(sqrt(num_face)));
bool arb = ofGetUsingArbTex();
ofDisableArbTex();
image.allocate(tex_size, tex_size, OF_IMAGE_COLOR);
if (arb) ofEnableArbTex();
mesh.clearTexCoords();
image.getPixelsRef().set(0);
float texel_size = (1. / image.getWidth()) * 0.5;
for (int i = 0; i < num_face; i++)
{
int u = (i % tex_size);
int v = (i / tex_size);
ofColor c = color[i * 3];
image.setColor(u, v, c);
float uu = (float)u / image.getWidth() + texel_size;
float vv = (float)v / image.getHeight() + texel_size;
mesh.addTexCoord(ofVec2f(uu, vv));
mesh.addTexCoord(ofVec2f(uu, vv));
mesh.addTexCoord(ofVec2f(uu, vv));
}
image.update();
mesh.clearColors();
}
示例5: drawContours
void ForbiddenPlanet::drawContours(float contrast, ofImage img,float sizeMultX,float sizeMultY, ofRectangle faceBoundingBox)
{
ofxCvGrayscaleImage faceImg;
faceImg.setFromPixels(img.getPixelsRef());
faceImg.brightnessContrast(0.05f,contrast);
contourFinder.findContours(faceImg, 5, (340*240), 45, true);
ofSetColor(200,0,50);
for (int i = 0; i < contourFinder.nBlobs; i++){
float lastX = 0;
float lastY = 0;
glBegin(GL_LINES);
for(int j =0; j < contourFinder.blobs[i].nPts;j++)
{
float x = FACE_TARGET_POS_X - (faceImg.width*sizeMultX)/2+ contourFinder.blobs[i].pts[j].x * sizeMultX;
float y = FACE_TARGET_POS_Y - (faceImg.height*sizeMultY)/2 + contourFinder.blobs[i].pts[j].y * sizeMultY;
if(ofDist(lastX,lastY,x,y) < 25.0 && (int)lastX != 0 && (int)lastY != 0)
{
glVertex2f(x,y);
glVertex2f(lastX,lastY);
}
lastX = x;
lastY = y;
//ofCurveVertex( contourFinder.blobs[i].pts[j].x, contourFinder.blobs[i].pts[j].y);
}
glEnd();
}
}
示例6: setImg
//--------------------------------------------------------------
void ofxAEOverlay::setImg(ofImage & i){
img.clear();
img.setFromPixels(i.getPixelsRef());
img.update();
}
示例7: draw
//--------------------------------------------
void ofCairoRenderer::draw(ofImage & img, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh){
ofPixelsRef raw = img.getPixelsRef();
bool shouldCrop = sx != 0 || sy != 0 || sw != w || sh != h;
ofPixels cropped;
if(shouldCrop) {
cropped.allocate(sw, sh, raw.getImageType());
raw.cropTo(cropped, sx, sy, sw, sh);
}
ofPixelsRef pix = shouldCrop ? cropped : raw;
pushMatrix();
translate(x,y,z);
scale(w/pix.getWidth(),h/pix.getHeight());
cairo_surface_t *image;
int stride=0;
int picsize = pix.getWidth()* pix.getHeight();
unsigned char *imgPix = pix.getPixels();
static vector<unsigned char> swapPixels;
switch(pix.getImageType()){
case OF_IMAGE_COLOR:
#ifdef TARGET_LITTLE_ENDIAN
swapPixels.resize(picsize * 4);
for(int p= 0; p<picsize; p++) {
swapPixels[p*4] = imgPix[p*3 +2];
swapPixels[p*4 +1] = imgPix[p*3 +1];
swapPixels[p*4 +2] = imgPix[p*3];
}
#else
swapPixels.resize(picsize * 4);
for(int p= 0; p<picsize; p++) {
swapPixels[p*4] = imgPix[p*3];
swapPixels[p*4 +1] = imgPix[p*3 +1];
swapPixels[p*4 +2] = imgPix[p*3 +2];
}
#endif
stride = cairo_format_stride_for_width (CAIRO_FORMAT_RGB24, pix.getWidth());
image = cairo_image_surface_create_for_data(&swapPixels[0], CAIRO_FORMAT_RGB24, pix.getWidth(), pix.getHeight(), stride);
break;
case OF_IMAGE_COLOR_ALPHA:
#ifdef TARGET_LITTLE_ENDIAN
swapPixels.resize(picsize * 4);
for(int p= 0; p<picsize; p++) {
swapPixels[p*4] = imgPix[p*4+2];
swapPixels[p*4 +1] = imgPix[p*4+1];
swapPixels[p*4 +2] = imgPix[p*4];
swapPixels[p*4 +3] = imgPix[p*4+3];
}
stride = cairo_format_stride_for_width (CAIRO_FORMAT_ARGB32, pix.getWidth());
image = cairo_image_surface_create_for_data(&swapPixels[0], CAIRO_FORMAT_ARGB32, pix.getWidth(), pix.getHeight(), stride);
#else
stride = cairo_format_stride_for_width (CAIRO_FORMAT_ARGB32, pix.getWidth());
image = cairo_image_surface_create_for_data(pix.getPixels(), CAIRO_FORMAT_ARGB32, pix.getWidth(), pix.getHeight(), stride);
#endif
break;
case OF_IMAGE_GRAYSCALE:
swapPixels.resize(picsize * 4);
for(int p= 0; p<picsize; p++) {
swapPixels[p*4] = imgPix[p];
swapPixels[p*4 +1] = imgPix[p];
swapPixels[p*4 +2] = imgPix[p];
}
stride = cairo_format_stride_for_width (CAIRO_FORMAT_RGB24, pix.getWidth());
image = cairo_image_surface_create_for_data(&swapPixels[0], CAIRO_FORMAT_RGB24, pix.getWidth(), pix.getHeight(), stride);
break;
case OF_IMAGE_UNDEFINED:
default:
ofLogError("ofCairoRenderer") << "draw(): trying to draw undefined image type " << pix.getImageType();
popMatrix();
return;
break;
}
cairo_set_source_surface (cr, image, 0,0);
cairo_paint (cr);
cairo_surface_flush(image);
cairo_surface_destroy (image);
popMatrix();
}
示例8: setFromImage
void ofxVectorField::setFromImage(ofImage & image) {
int imgW = image.width;
int imgH = image.height;
int imgPixelCount = imgW * imgH;
if( !bIsAllocated) {
printf("ofxVectorField not allocated -- allocating automatically using default spacing\n");
setup(imgW, imgH, OFX_VECFIELD_DEFALT_SPACING);
}
// storage for brightness
unsigned char * imagePixels = image.getPixels();
unsigned char brightness[imgPixelCount];
if( image.getPixelsRef().getImageType() == OF_IMAGE_GRAYSCALE) {
for(int x=0; x<imgW; x++) {
for(int y=0; y<imgH; y++) {
int srcPos = y * imgW + x;
unsigned char b = imagePixels[srcPos];
brightness[srcPos] = b;
}
}
} else {
// convert RGB to luma
unsigned char * imagePixels = image.getPixels();
unsigned char brightness[imgPixelCount];
int bpp = image.getPixelsRef().getBytesPerPixel();
for(int x=0; x<imgW; x++) {
for(int y=0; y<imgH; y++) {
int dstPos = y * imgW + x;
int srcPos = dstPos * 3;
unsigned char r = imagePixels[srcPos];
unsigned char g = imagePixels[srcPos+1];
unsigned char b = imagePixels[srcPos+2];
brightness[dstPos] = ( r * 0.299) + (.587 * g) + (.114 * b);
}
}
}
// detetermine the vector at each position in the image
for(int x=1; x<width-1; x++) {
for(int y=1; y<height-1; y++) {
int vecPos = y * width + x;
char areaPixels[9];
// loop through the area pixels
for(int i=-1; i<=1; i++) {
for(int j=-1; j<=1; j++) {
// determine where to read from in the area (not optimized)
int readPos = ((y + j) * spacing * imgW + (x + i)*spacing) * 3;
unsigned char R = imagePixels[readPos];
unsigned char G = imagePixels[readPos+1];
unsigned char B = imagePixels[readPos+2];
char BR = (0.299 * R) + (.587 * G) + (.114 * B);
int writePos = (j+1) * 3 + (i + 1);
areaPixels[writePos] = BR;
}
}
float dX = (areaPixels[0] + areaPixels[3] + areaPixels[6])/3 - (areaPixels[2] + areaPixels[5] + areaPixels[8])/3;
float dY = (areaPixels[0] + areaPixels[1] + areaPixels[2])/3 - (areaPixels[6] + areaPixels[7] + areaPixels[8])/3;
vectorField[vecPos].x = dY;
vectorField[vecPos].y = dX;
}
}
// copy pixels to the top and bottom
for(int x=0; x<width; x++) {
int dstPos = x;
int srcPos = x + width;
vectorField[dstPos].x = vectorField[srcPos].x;
vectorField[dstPos].y = vectorField[srcPos].y;
dstPos = x + (height-1)*width;
srcPos = x + (height-2)*width;
vectorField[dstPos].x = vectorField[srcPos].x;
//.........这里部分代码省略.........
示例9: draw
//--------------------------------------------
void ofCairoRenderer::draw(ofImage & img, float x, float y, float z, float w, float h){
ofPixelsRef pix = img.getPixelsRef();
pushMatrix();
translate(x,y,z);
scale(w/pix.getWidth(),h/pix.getHeight());
cairo_surface_t *image;
int stride=0;
int picsize = pix.getWidth()* pix.getHeight();
unsigned char *imgPix = pix.getPixels();
static vector<unsigned char> swapPixels;
switch(pix.getImageType()){
case OF_IMAGE_COLOR:
#ifdef TARGET_LITTLE_ENDIAN
swapPixels.resize(picsize * 4);
for(int p= 0; p<picsize; p++) {
swapPixels[p*4] = imgPix[p*3 +2];
swapPixels[p*4 +1] = imgPix[p*3 +1];
swapPixels[p*4 +2] = imgPix[p*3];
}
#else
swapPixels.resize(picsize * 4);
for(int p= 0; p<picsize; p++) {
swapPixels[p*4] = imgPix[p*3];
swapPixels[p*4 +1] = imgPix[p*3 +1];
swapPixels[p*4 +2] = imgPix[p*3 +2];
}
#endif
stride = cairo_format_stride_for_width (CAIRO_FORMAT_RGB24, pix.getWidth());
image = cairo_image_surface_create_for_data(&swapPixels[0], CAIRO_FORMAT_RGB24, pix.getWidth(), pix.getHeight(), stride);
break;
case OF_IMAGE_COLOR_ALPHA:
#ifdef TARGET_LITTLE_ENDIAN
swapPixels.resize(picsize * 4);
for(int p= 0; p<picsize; p++) {
swapPixels[p*4] = imgPix[p*4+2];
swapPixels[p*4 +1] = imgPix[p*4+1];
swapPixels[p*4 +2] = imgPix[p*4];
swapPixels[p*4 +3] = imgPix[p*4+3];
}
stride = cairo_format_stride_for_width (CAIRO_FORMAT_ARGB32, pix.getWidth());
image = cairo_image_surface_create_for_data(&swapPixels[0], CAIRO_FORMAT_ARGB32, pix.getWidth(), pix.getHeight(), stride);
#else
stride = cairo_format_stride_for_width (CAIRO_FORMAT_ARGB32, pix.getWidth());
image = cairo_image_surface_create_for_data(pix.getPixels(), CAIRO_FORMAT_ARGB32, pix.getWidth(), pix.getHeight(), stride);
#endif
break;
case OF_IMAGE_GRAYSCALE:
swapPixels.resize(picsize * 4);
for(int p= 0; p<picsize; p++) {
swapPixels[p*4] = imgPix[p];
swapPixels[p*4 +1] = imgPix[p];
swapPixels[p*4 +2] = imgPix[p];
}
stride = cairo_format_stride_for_width (CAIRO_FORMAT_RGB24, pix.getWidth());
image = cairo_image_surface_create_for_data(&swapPixels[0], CAIRO_FORMAT_RGB24, pix.getWidth(), pix.getHeight(), stride);
break;
case OF_IMAGE_UNDEFINED:
ofLog(OF_LOG_ERROR,"ofCairoRenderer: trying to render undefined type image");
popMatrix();
return;
break;
}
cairo_set_source_surface (cr, image, 0,0);
cairo_paint (cr);
cairo_surface_flush(image);
cairo_surface_destroy (image);
popMatrix();
}
示例10: pushFrame
//------------------------------------------------------------------------------
void ofxIpVideoServerRoute::pushFrame(ofImage& img) {
pushFrame(img.getPixelsRef());
}
示例11: resize
void resize(ofImage& source, ofImage& destination, float xScale, float yScale, int interpolation) {
ofImageType sourceType = source.getPixelsRef().getImageType();
destination.allocate(source.getWidth() * xScale, source.getHeight() * yScale, sourceType);
resize(source, destination, interpolation);
}
示例12: saveFace
void saveFace(FaceTrackerData& data, ofImage& img) {
string basePath = ofGetTimestampString("%Y.%m.%d/%H.%M.%S.%i");
data.save("metadata/" + basePath + ".face");
imageSaver.saveImage(img.getPixelsRef(), data.getImageFilename());
}
示例13: setImage
void ofxJpegGlitch::setImage(ofImage &image) {
ofSaveImage(image.getPixelsRef(), buf, OF_IMAGE_FORMAT_JPEG);
}