本文整理汇总了C++中ofImage::getPixels方法的典型用法代码示例。如果您正苦于以下问题:C++ ofImage::getPixels方法的具体用法?C++ ofImage::getPixels怎么用?C++ ofImage::getPixels使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ofImage
的用法示例。
在下文中一共展示了ofImage::getPixels方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: invert
ofTexture ofxImageTS::invert(ofImage image){
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){
copy[i] = 255 - image.getPixels()[i];
copy[i+1] = 255 - image.getPixels()[i+1];
copy[i+2] = 255 - image.getPixels()[i+2];
}
texture.loadData(copy);
return texture;
}
示例2: greyScale
ofTexture ofxImageTS::greyScale(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;
copy[i] = avg;
copy[i+1] = avg;
copy[i+2] = avg;
}
texture.loadData(copy);
return texture;
}
示例3: tanGB
ofTexture ofxImageTS::tanGB(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] = Tan * image.getPixels()[i+1];
copy[i+2] = Tan * image.getPixels()[i+2];
}
texture.loadData(copy);
return texture;
}
示例4: setBrightness
//--------------------------------------------------------------
ofImage ofxContrast::setBrightness(ofImage& _img, float brightnessAmount){
ofxCvColorImage cvimg;
cvimg.allocate(_img.width, _img.height);
cvimg.setFromPixels(_img.getPixels(), _img.width, _img.height);
float brightnessVal = MAX(-127, MIN(127, brightnessAmount));
unsigned char data[ 256 ];
CvMat * matrix;
matrix = cvCreateMatHeader( 1, 256, CV_8UC1 );
cvSetData( matrix, data, 0 );
for( int i=0; i<256; i++ ) {
int value = cvRound( i+brightnessVal );
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;
}
示例5: 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;
}
示例6: addFrame
void ofxQTVideoSaver::addFrame(ofImage newImg){
// downscale if dims dont match
if(newImg.width != vidOutputWidth || newImg.height != vidOutputHeight){
// resize image before output
newImg.resize(vidOutputWidth, vidOutputHeight);
}
video.addFrame(newImg.getPixels(), 1.0f / vidFrameRate);
numRecordedFrames++;
if(numRecordedFrames % videoFrameLength == 0 ) {
numRecordedFrames = 1;
string vidName = vidDir + "/"+ vidNamePrefix + ofToString(curVideoNum) +".mov";
printf("save curVideoNum \n");
// Save the movie to disk
video.finishMovie();
video.setup(vidOutputWidth,vidOutputHeight,vidName);
curVideoNum++;
if(curVideoNum > maxVideos) {
/* clean up code should start to run here*/
/* this class will infinitly create mov files so you might want to delete some
after a few have been made
*/
};
}
}
示例7: saveStencilToHex
string ofxBaseGui::saveStencilToHex(ofImage& img) {
stringstream strm;
int width = img.getWidth();
int height = img.getHeight();
int n = width * height;
unsigned char cur = 0;
int shift = 0;
strm << "{";
for(int i = 0; i < n;) {
if(img.getPixels()[i * 4 + 3] > 0) {
cur |= 1 << shift;
}
i++;
if(i % 8 == 0) {
strm << "0x" << hex << (unsigned int) cur;
cur = 0;
shift = 0;
if(i < n) {
strm << ",";
}
} else {
shift++;
}
}
strm << "}";
return strm.str();
}
示例8: sinusoidal
ofTexture ofxImageTS::sinusoidal(ofImage image){
ofTexture texture;
ofPixels copy;
copy.allocate(image.getWidth(), image.getHeight(), OF_PIXELS_RGB);
texture.allocate(image);
float Sin;
for(int i = 0; i < image.getPixels().size()-3; i += 3){
Sin = (sin(i) + 1)/2.0f;
copy[i] = Sin * image.getPixels()[i];
copy[i+1] = Sin * image.getPixels()[i+1];
copy[i+2] = Sin * image.getPixels()[i+2];
}
texture.loadData(copy);
return texture;
}
示例9: colorWiring
// image2data converts an image to OctoWS2811's raw data format.
// The number of vertical pixels in the image must be a multiple
// of 8. The data array must be the proper size for the image.
//--------------------------------------------------------------
void ofxTeensyOcto::image2data(ofImage image, unsigned char* data, bool layout)
{
int offset = 3;
int x, y, xbegin, xend, xinc, mask;
int linesPerPin = image.getHeight() / 8;
int* pixel = new int[8];
// get the copied image pixels
pixels2 = image.getPixels();
// 2d array of our pixel colors
for (int x = 0; x < ledWidth; x++)
{
for (int y = 0; y < (ledHeight * stripsPerPort * numPortsMain); y++)
{
int loc = x + y * ledWidth;
colors[loc] = pixels2.getColor(x, y);
}
}
for (y = 0; y < linesPerPin; y++)
{
if ((y & 1) == (layout ? 0 : 1))
{
// even numbered rows are left to right
xbegin = 0;
xend = image.getWidth();
xinc = 1;
}
else
{
// odd numbered rows are right to left
xbegin = image.getWidth() - 1;
xend = -1;
xinc = -1;
}
for (x = xbegin; x != xend; x += xinc)
{
for (int i=0; i < 8; i++)
{
int temploc = x + (y + linesPerPin * i) * image.getWidth();
pixel[i] = colors[temploc].getHex();
pixel[i] = colorWiring(pixel[i]);
}
// convert 8 pixels to 24 bytes
for (mask = 0x800000; mask != 0; mask >>= 1)
{
unsigned char b = 0;
for (int i=0; i < 8; i++)
{
if ((pixel[i] & mask) != 0) b |= (1 << i);
}
data[offset++] = b;
}
}
}
}
示例10: addFrame
void ofxGifEncoder::addFrame(ofImage & img, float _duration) {
if(img.width != w || img.height != h) {
ofLog(OF_LOG_WARNING, "ofxGifEncoder::addFrame image dimensions don't match, skipping frame");
return;
}
addFrame(img.getPixels(), w, h, img.bpp, _duration);
}
示例11: detect
//-----------------------------------------------------
void ofxSURFTracker::detect(ofImage &img) {
int inputWidth = img.getWidth();
int inputHeight = img.getHeight();
if(inputWidth < width || inputHeight < height) {
return; // detection impossible, because I can't crop out of this image
}
detect(img.getPixels(), inputWidth, inputHeight);
}
示例12: setup
//--------------------------------------------------------------
void testApp::setup(){
quadmesh.create(150, 50, 400, 300, 8);
quadimage.loadImage("1.jpg");
quadtexture = genTex(quadimage.getWidth(), quadimage.getHeight(), quadimage.getPixels());
// if use GL_TEXTURE_RECTANGLE, change texture coord from [1,1] to [width, height]
//quadmesh.ResetTextureCoords(quadimage.getWidth(), quadimage.getHeight());
}
示例13: getImage
//--------------------------------------------------------------
// create a visual representation of the simulation
void Rd::getImage(ofImage & image, const ofColor & c1, const ofColor & c2){
unsigned char * pixels = image.getPixels();
for(int indexImg = 0, indexA = 0; indexA < A.size(); indexImg += 3, indexA++){
ofColor c = c1.getLerped(c2, A[indexA] * A[indexA]);
pixels[indexImg] = c.r;
pixels[indexImg + 1] = c.b;
pixels[indexImg + 2] = c.g;
}
image.update();
}
示例14: update
void ofApp::update() {
step();
unsigned char* pixels = buffer.getPixels();
int n = num * num;
for (int i = 0; i < n; i++) {
pixels[i] = 128 + 100*grid[i];
}
buffer.update();
}
示例15: getOneShot
void ofxLibdc::getOneShot(ofImage& img) {
setTransmit(false);
flush();
dc1394_video_set_one_shot(camera, DC1394_ON);
dc1394video_frame_t *frame;
dc1394_capture_dequeue(camera, DC1394_CAPTURE_POLICY_WAIT, &frame);
img.allocate(width, height, imageType);
if(imageType == OF_IMAGE_GRAYSCALE) {
memcpy(img.getPixels(), frame->image, width * height);
} else if(imageType == OF_IMAGE_COLOR) {
// this shouldn't be reallocated every frame!
dc1394video_frame_t* rgbFrame = (dc1394video_frame_t*) calloc(1, sizeof(dc1394video_frame_t));
rgbFrame->color_coding = DC1394_COLOR_CODING_RGB8;
dc1394_convert_frames(frame, rgbFrame);
memcpy(img.getPixels(), rgbFrame->image, 3 * width * height);
free(rgbFrame);
}
img.setFromPixels(frame->image, width, height, imageType);
dc1394_capture_enqueue(camera, frame);
}