本文整理汇总了C++中ofImage类的典型用法代码示例。如果您正苦于以下问题:C++ ofImage类的具体用法?C++ ofImage怎么用?C++ ofImage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ofImage类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: tanB
ofTexture ofxImageTS::tanB(ofImage image){
ofTexture texture;
ofPixels copy;
copy.allocate(image.getWidth(), image.getHeight(), OF_PIXELS_RGB);
texture.allocate(image);
float Tan;
for(int i = 0; i < image.getPixels().size()-3; i += 3){
Tan = tan(i);
copy[i] = image.getPixels()[i];
copy[i+1] = image.getPixels()[i+1];
copy[i+2] = Tan * image.getPixels()[i+2];
}
texture.loadData(copy);
return texture;
}
开发者ID:essteban,项目名称:ofxImageTS,代码行数:16,代码来源:ofxImageTS.cpp
示例2: noise
ofTexture ofxImageTS::noise(ofImage image, float mix) {
float avg;
ofTexture texture;
ofPixels copy;
copy.allocate(image.getWidth(), image.getHeight(), OF_PIXELS_RGB);
texture.allocate(image);
for(int i = 0; i < image.getPixels().size()-3; i += 3){
avg = (image.getPixels()[i] + image.getPixels()[i+1] + image.getPixels()[i+2])/3.0f;
copy[i] = avg * (125 - avg) * mix;
copy[i+1] = avg * (125 - avg) * mix;
copy[i+2] = avg * (125 - avg) * mix;
}
texture.loadData(copy);
return texture;
}
开发者ID:essteban,项目名称:ofxImageTS,代码行数:16,代码来源:ofxImageTS.cpp
示例3: MAX
//--------------------------------------------------------------
ofImage ofxContrast::setBrightnessAndContrast(ofImage& _img, float brightnessAmount, float contrastAmount){
ofxCvColorImage cvimg;
cvimg.allocate(_img.width, _img.height);
cvimg.setFromPixels(_img.getPixels(), _img.width, _img.height);
float brightnessVal = MAX(-127, MIN(127, brightnessAmount));
float contrastVal = MAX(-127, MIN(127, contrastAmount));
unsigned char data[ 256 ];
CvMat * matrix;
double delta, a, b;
matrix = cvCreateMatHeader( 1, 256, CV_8UC1 );
cvSetData( matrix, data, 0 );
if ( contrastVal>0 ) {
delta = (127.0f*contrastVal) / 128.0f;
a = 255.0f / ( 255.0f-(delta*2.0f) );
b = a * (brightnessVal-delta);
}
else {
delta = (-128.0f*contrastVal) / 128.0f;
a = ( 256.0f-(delta*2.0f) ) / 255.0f;
b = ( a*brightnessVal )+delta;
}
for( int i=0; i<256; i++ ) {
int value = cvRound( (a*i)+b );
data[i] = (unsigned char) min( max(0,value), 255 );
}
cvLUT( cvimg.getCvImage(), cvimg.getCvImage(), matrix );
cvReleaseMat( &matrix );
ofImage ofimg;
ofimg.allocate(_img.width, _img.height, OF_IMAGE_COLOR);
ofimg.setFromPixels(cvimg.getPixels(), _img.width, _img.height, OF_IMAGE_COLOR);
return ofimg;
}
开发者ID:KazuyoshiUeno,项目名称:ofxContrast,代码行数:40,代码来源:ofxContrast.cpp
示例4: ofLog
bool ofxEpilog::send(ofImage img, int w_mm, int h_mm)
{
//
// TODO([email protected]): finish implementation
//
if(!img.isAllocated())
return false;
if(w_mm <= 0 || h_mm <= 0)
return false;
ofLog(OF_LOG_WARNING) << "bool ofxEpilog::send(ofImage img, int w_mm, int h_mm) is not implemented yet.";
return false;
//
// dummy implementation
//
ofBuffer buffer;
buffer.append(createPayloadHeader(getMachineProfile(), getOutputConfig()));
// create raster part
buffer.append(createPayloadRasterBody(img, getOutputConfig()));
// end raster part regardless of it's empty
buffer.append(PCL_RASTER_END);
// begin HPGL commands (vector part)
buffer.append(HPGL_START);
buffer.append(HPGL_VECTOR_INIT + HPGL_CMD_DELIMITER);
if(!keep_alive)
buffer.append(createPayloadFooter()); // end the session
if(pjl_file.get() != NULL)
pjl_file->writeFromBuffer(buffer);
return tcp_client.sendRaw(buffer);
}
开发者ID:YCAMInterlab,项目名称:ofxEpilog,代码行数:39,代码来源:ofxEpilog.cpp
示例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();
}
}
开发者ID:jaysonh,项目名称:BFIInstallation,代码行数:37,代码来源:ForbiddenPlanet.cpp
示例6: drawSampleImage
void ParticleTrace :: drawSampleImage ( ofImage& img )
{
int w = sampleGridW;
int h = sampleGridH;
int b = img.bpp / 8;
unsigned char* pixels = img.getPixels();
for( int y=0; y<img.height; y++ )
{
for( int x=0; x<img.width; x++ )
{
int p = ( y * img.width + x ) * b;
if( img.type == OF_IMAGE_GRAYSCALE )
{
ofSetColor( pixels[ p ], pixels[ p ], pixels[ p ] );
}
else if( img.type == OF_IMAGE_COLOR )
{
ofSetColor( pixels[ p + 0 ], pixels[ p + 1 ], pixels[ p + 2 ] );
}
else if( img.type == OF_IMAGE_COLOR_ALPHA )
{
ofSetColor( pixels[ p + 0 ], pixels[ p + 1 ], pixels[ p + 2 ], pixels[ p + 3 ] );
}
ofFill();
ofRect( x * w, y * h, w, h );
ofNoFill();
ofSetColor( 100, 100, 100 );
ofRect( x * w, y * h, w, h );
}
}
}
开发者ID:MrMdR,项目名称:julapy,代码行数:36,代码来源:ParticleTrace.cpp
示例7: 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();
}
开发者ID:hanasaan,项目名称:ofxObjLoader,代码行数:38,代码来源:ofxObjLoader.cpp
示例8: dualist
ofTexture ofxImageTS::dualist(ofImage image, ofColor base, ofColor top) {
int avg;
ofTexture texture;
ofPixels copy;
copy.allocate(image.getWidth(), image.getHeight(), OF_PIXELS_RGB);
texture.allocate(image);
for(int i = 0; i < image.getPixels().size()-3; i += 3){
avg = (image.getPixels()[i] + image.getPixels()[i+1] + image.getPixels()[i+2])/3;
if(avg < 128) {
copy[i] = base.r;
copy[i+1] = base.g;
copy[i+2] = base.b;
}
else {
copy[i] = top.r;
copy[i+1] = top.g;
copy[i+2] = top.b;
}
}
texture.loadData(copy);
return texture;
}
开发者ID:essteban,项目名称:ofxImageTS,代码行数:22,代码来源:ofxImageTS.cpp
示例9: whiteBlack
ofTexture ofxImageTS::whiteBlack(ofImage image) {
int avg;
ofTexture texture;
ofPixels copy;
copy.allocate(image.getWidth(), image.getHeight(), OF_PIXELS_RGB);
texture.allocate(image);
for(int i = 0; i < image.getPixels().size()-3; i += 3){
avg = (image.getPixels()[i] + image.getPixels()[i+1] + image.getPixels()[i+2])/3;
if(avg >= 128) {
copy[i] = 254;
copy[i+1] = 254;
copy[i+2] = 254;
}
else {
copy[i] = 0;
copy[i+1] = 0;
copy[i+2] = 0;
}
}
texture.loadData(copy);
return texture;
}
开发者ID:essteban,项目名称:ofxImageTS,代码行数:23,代码来源:ofxImageTS.cpp
示例10: loadImageRaw
void loadImageRaw(string path, int w, int h, ofImage &img) {
ofFile file(path);
img.setFromPixels((unsigned char*)file.readToBuffer().getData(), w, h, OF_IMAGE_COLOR);
}
开发者ID:gorkacortazar,项目名称:ofxMSATensorFlow,代码行数:4,代码来源:ofApp.cpp
示例11:
void ofxOpticalFlowLK :: update ( ofImage& source )
{
update( source.getPixels(), source.width, source.height, source.type );
}
开发者ID:MaxWorgan,项目名称:ofxOpticalFlowLK,代码行数:4,代码来源:ofxOpticalFlowLK.cpp
示例12: loadImage
GLuint ofxImGui::loadImage(ofImage& image)
{
if(!engine) return -1;
return loadPixels(image.getPixels());
}
开发者ID:4ker,项目名称:ofxImGui,代码行数:5,代码来源:ofxImGui.cpp
示例13: 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;
//.........这里部分代码省略.........
开发者ID:loveq369,项目名称:GAmuza,代码行数:101,代码来源:ofxVectorField.cpp
示例14: Rectify_Image
void ofxCorrectPerspective::Rectify_Image(ofImage & my_image,double focal_length,double sensor_width, double & alpha, double & beta){
resize_image=1; //To Enable or Disable Resize
//Rescale Image to be Max in 1000px
if (resize_image && max(my_image.width,my_image.height)>1000)
{
float s=float(1000)/max(my_image.width,my_image.height);
my_image.resize(floor(my_image.width*s),floor(my_image.height*s));
}
float f=focal_length*(float)max(my_image.width,my_image.height)/sensor_width;
K.set(f,0.0,0.0,0.0,f,0.0,0.0,0.0,1.0);
center.set(double(my_image.width)/2.0,double(my_image.height)/2.0);
if (talk) cout << K;
my_img_gray=my_image;
my_img_gray.setImageType(OF_IMAGE_GRAYSCALE);
//Converting Image to Image Double//
image_double dub_image;
ntuple_list lsd_out;
unsigned int w=my_img_gray.width;
unsigned int h=my_img_gray.height;
unsigned char * imgP=my_img_gray.getPixels();
// LSD parameters start
double scale = 0.8; // Scale the image by Gaussian filter to 'scale'.
double sigma_scale = 0.6; // Sigma for Gaussian filter is computed as sigma = sigma_scale/scale.
double quant = 2.0; // Bound to the quantization error on the gradient norm.
double ang_th = 22.5; // Gradient angle tolerance in degrees.
double eps = 0.0; // Detection threshold, -log10(NFA).
double density_th = 0.7; // Minimal density of region points in rectangle.
int n_bins = 1024; // Number of bins in pseudo-ordering of gradient modulus.
double max_grad = 255.0; // Gradient modulus in the highest bin. The default value corresponds to the highest
// gradient modulus on images with gray levels in [0,255].
// LSD parameters end
bool verbose=0;
dub_image = new_image_double(w,h);
double px=0;
cout << "\n--------\nInput data being written to image buffer \n";
for(int j=0;j<(w*h);j++){
px=imgP[j];
dub_image->data[j] = px;
if (verbose){
cout << " " << dub_image->data[j];
}
}
// Call LSD //
lsd_out = LineSegmentDetection( dub_image, scale, sigma_scale, quant, ang_th, eps,
density_th, n_bins, max_grad, NULL );
cout << "LSD has done it's thing!\n";
if (talk) cout << "Number of Lines: "<< lsd_out->size << "Number of Dimensions: " << lsd_out->dim << "\n";
if (verbose)
{
cout << "LSD Values: " << lsd_out->values[0] << " " << lsd_out->values[1] <<" " << lsd_out->values[2] <<" " << lsd_out->values[3] <<" " << lsd_out->values[4] <<" " << lsd_out->values[5] << "\n";
}
//Sorting in (Value, Index) pairs
//http://stackoverflow.com/questions/1577475/c-sorting-and-keeping-track-of-indexes
std::vector<mypair> line_lengths;
double sqd_distance;
mesh.setMode(OF_PRIMITIVE_LINES);
mesh.enableColors();
ofVec3f first(0.0,0.0,0.0);
ofVec3f second(0.0,0.0,0.0);
double x1,x2,y1,y2;
for(int j=0;j<(lsd_out->size*lsd_out->dim);j=j+5){
x1=lsd_out->values[j];
y1=lsd_out->values[j+1];
x2=lsd_out->values[j+2];
y2=lsd_out->values[j+3];
sqd_distance=(x2-x1)*(x2-x1) + (y2-y1)*(y2-y1);
line_lengths.push_back(make_pair(sqd_distance,j));
//To Draw as Primitive Lines//
/*first.set(x2,y2,0.0);
second.set(x1,y1,0.0);
mesh.addVertex(first);
mesh.addColor(ofFloatColor(1.0, 0.0, 0.0));
mesh.addVertex(second);
mesh.addColor(ofFloatColor(1.0, 0.0, 0.0));*/
//Lines Added, will be drawn//
}
sort(line_lengths.begin(),line_lengths.end());
reverse(line_lengths.begin(), line_lengths.end());
if (talk) cout << line_lengths[0].first << " " << line_lengths[0].second << " " << line_lengths[1].first << " " << line_lengths[1].second << "\n";
unsigned int maxlines=700;
unsigned int no_of_lines=min(lsd_out->size,maxlines);
//Store these Lines pairs in a Matrix, in descending order of Distance
cout << "Number of Lines: " << no_of_lines << "\n";
L.resize(4);
//.........这里部分代码省略.........
开发者ID:jack06215,项目名称:Matlab-Workstation,代码行数:101,代码来源:2dRect.cpp
示例15: pushFrame
//------------------------------------------------------------------------------
void ofxIpVideoServerRoute::pushFrame(ofImage& img) {
pushFrame(img.getPixelsRef());
}
开发者ID:bakercp,项目名称:ofxIpVideoServer,代码行数:4,代码来源:ofxIpVideoServerRoute.cpp
示例16: setColorFromFrame
void ckvdTileGrabber::setColorFromFrame(ofImage& frame)
{
_fixture.setVideoRect(x - width/2, y - height/2, width, height);
_fixture.setSourceData(frame.getPixels(), frame.width, frame.height, 3);
}
开发者ID:catvvvveasel,项目名称:streetlight,代码行数:5,代码来源:ckvdHandle.cpp
示例17: draw
//--------------------------------------------
void ofCairoRenderer::draw(const ofImage & img, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const{
draw(img.getPixels(),x,y,z,w,h,sx,sy,sw,sh);
}
开发者ID:8morikazuto,项目名称:openFrameworks,代码行数:4,代码来源:ofCairoRenderer.cpp
示例18: 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();
}
开发者ID:AppleToolbox,项目名称:openFrameworks,代码行数:84,代码来源:ofCairoRenderer.cpp
示例19: draw
//----------------------------------------------------------
void ofGLRenderer::draw(ofImage & image, float x, float y, float z, float w, float h){
if(image.isUsingTexture()){
image.getTextureReference().draw(x,y,z,w,h);
}
}
开发者ID:AsherBond,项目名称:openFrameworks,代码行数:6,代码来源:ofGLRenderer.cpp
示例20: setImg
//--------------------------------------------------------------
void ofxAEOverlay::setImg(ofImage & i){
img.clear();
img.setFromPixels(i.getPixelsRef());
img.update();
}
开发者ID:roymacdonald,项目名称:ofxAfterEffectsTransforms,代码行数:6,代码来源:ofxAEOverlay.cpp
注:本文中的ofImage类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论