本文整理汇总了C++中ofImage::setFromPixels方法的典型用法代码示例。如果您正苦于以下问题:C++ ofImage::setFromPixels方法的具体用法?C++ ofImage::setFromPixels怎么用?C++ ofImage::setFromPixels使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ofImage
的用法示例。
在下文中一共展示了ofImage::setFromPixels方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: show_merge
void ofApp::show_merge(int play_cnt) {
memcpy(tmp, recorded + image_size * play_cnt, image_size);
memcpy(merged, show, image_size);
bgs(tmp);
image_merge(merged, tmp, 0);
img.setFromPixels(merged, width, height, OF_IMAGE_COLOR);
img.draw(width, height);
}
示例2: getImage
void activations::getImage(ofImage & img) {
ofPixels pix;
pix.allocate(rows, cols, OF_PIXELS_GRAY);
for (int i=0; i<rows*cols; i++) {
pix[i] = ofMap(acts[i], min, max, 0, 255);
}
img.setFromPixels(pix);
}
示例3: update
void testApp::update() {
if(wrapper.isFrameNew())
{
timer.tick();
}
ofSetWindowTitle("FPS:" + ofToString(ofGetFrameRate()));
cameraImage.setFromPixels(wrapper.pixels, wrapper.cameraWidth, wrapper.cameraHeight, OF_IMAGE_COLOR);
}
示例4: update
//--------------------------------------------------------------
void testApp::update()
{
subs.update();
if (subs.isFrameNew())
{
image.setFromPixels(subs.getPixelsRef());
}
ofSetWindowTitle(ofToString(subs.getFps(), 2));
}
示例5: makeThumb
void makeThumb(string vidPath, string thumb){
ofVideoPlayer tmp;
tmp.loadMovie(vidPath);
tmp.play();
tmp.setPosition(0.3);
ofImage img;
img.setFromPixels( tmp.getPixelsRef() );
img.resize(120, 120.0f * (img.getHeight() / img.getWidth()) );
img.saveImage(thumb);
}
示例6: setup
//--------------------------------------------------------------
void testApp::setup(){
ofEnableAlphaBlending();
//load image file
string path = ofToDataPath("logo.png");
of_image.loadImage( path );
ci_surface = ci::loadImage( path );
//convert images
ci_texture = ci::gl::Texture( ofxCi::toCi(of_image), GL_RGBA, of_image.getWidth(), of_image.getHeight() );
of_image.setFromPixels(ofxCi::toOf(ci_surface), ci_surface.getWidth(), ci_surface.getHeight(), OF_IMAGE_COLOR_ALPHA);
}
示例7: update
//--------------------------------------------------------------
void ofApp::update(){
//Creating image
int w = 512; //Image width
int h = 512; //Image height
//Allocate array for filling pixels data
unsigned char *data = new unsigned char[w * h * 4];
//Fill array for each pixel (x,y)
for (int y=0; y<h; y++) {
for (int x=0; x<w; x++) {
//Compute preliminary values,
//needed for our pixel color calculation:
//1. Time from application start
float time = ofGetElapsedTimef();
//2. Level of hyperbola value of x and y with
//center in w/2, h/2
float v = ( x - w/2 ) * ( y - h/2 );
//3. Combining v with time for motion effect
float u= v * 0.00025 + time;
//Here 0.00025 was chosen empirically
//4. Compute color components as periodical
//functions of u, and stretched to [0..255]
int red = ofMap( sin( u ), -1, 1, 0, 255 );
int green = ofMap( sin( u * 2 ), -1, 1, 0, 255 );
int blue = 255 - green;
int alpha = 255; //Just constant for simplicity
//Fill array components for pixel (x, y):
int index = 4 * ( x + w * y );
data[ index ] = red;
data[ index + 1 ] = green;
data[ index + 2 ] = blue;
data[ index + 3 ] = alpha;
}
}
//Load array to image
image.setFromPixels( data, w, h, OF_IMAGE_COLOR_ALPHA );
//Array is not needed anymore, so clear memory
delete[] data;
}
示例8: update
//--------------------------------------------------------------
void testApp::update(){
video.update();
if ( bVideoSetup && video.isFrameNew() ){
static unsigned long size;
static ofImage currentImage;
currentImage.setFromPixels(video.getPixelsRef());
// compress video into image via turbojpg
// the second param == quality. play with this to get a better framerate
// you can also try resizing your image!
//currentImage.resize(160, 120);
unsigned char * compressed = turbo.compress(¤tImage,50,&size);
server.sendBinary(compressed, size);
free(compressed);
}
}
示例9: 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);
}
示例10: draw
//--------------------------------------------------------------
void ofApp::draw(){
img.setFromPixels(show, width, height, OF_IMAGE_COLOR);
img.draw(width * 2, 0);
// save_image(img);
if (rec_flag) {
record();
}
if (play_cnt++ >= play_margin || play_cnt >= record_size) {
play_cnt = 0;
play_start = get_start_point();
}
show_cut(play_start + play_cnt);
show_bgs();
show_back();
show_merge(play_start + play_cnt);
// text
ofDrawBitmapString("play_cnt:" + ofToString(play_cnt), 0, 10);
ofDrawBitmapString("record_cnt:" + ofToString(rec_cnt), 0, 20);
ofDrawBitmapString("R", trackers[0].x, trackers[0].y);
ofDrawBitmapString("G", trackers[1].x, trackers[1].y);
ofDrawBitmapString("B", trackers[2].x, trackers[2].y);
}
示例11: 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);
}
示例12: show_back
void ofApp::show_back() {
img.setFromPixels(back, width, height, OF_IMAGE_COLOR);
img.draw(0, height);
}
示例13: show_bgs
void ofApp::show_bgs() {
memcpy(tmp, show, image_size);
bgs(tmp);
img.setFromPixels(tmp, width, height, OF_IMAGE_COLOR);
img.draw(0, 0);
}
示例14: show_cut
void ofApp::show_cut(int play_cnt) {
memcpy(tmp, recorded + image_size * play_cnt, image_size);
bgs(tmp);
img.setFromPixels(tmp, width, height, OF_IMAGE_COLOR);
img.draw(width, 0);
}
示例15: Rectify_Image
//.........这里部分代码省略.........
r_ind2=floor(ofRandom(ac.size()));
r1=ar[r_ind1];
r2=ar[r_ind2];
r3=ac[r_ind1];
r4=ac[r_ind2];
modelX=fitFunc4Lines(L_vec, r1, r2, r3, r4, f); //Fitting Function
distFunc(L_vec,modelX,f,thresh,arIn,acIn);
score=arIn.size();
//score=distFunc2(L_vec,modelX,f,thresh,arIn,acIn, ar, ac); //Distance Function
if (Bestscore<score)
{
Bestscore=score;
Best_arIn=arIn;
Best_acIn=acIn;
Best_modelX=modelX;
if (talk) cout << "No. of Inliers: "<< Bestscore<<endl;
}
trialcount++;
}
cout << "RANSAC Done." << endl;
cout << "No. of Inliers: "<< Bestscore<<endl;
column_vector solution=Best_modelX;
if (talk) cout << "cost_function solution:\n" << Best_modelX << endl;
cout << "cost_function solution:\n" << solution << endl;
alpha=solution(0);
beta=solution(1);
//APPLYING HOMOGRAPHY for this SOLUTION//
ofMatrix4x4 R=ofMatrix4x4::newRotationMatrix(solution(0)*180.0/PI, ofVec3f(-1, 0, 0), solution(1)*180.0/PI, ofVec3f(0, -1, 0), 0, ofVec3f(0, 0, -1));
double m[3][3] = {{R(0,0), R(0,1), R(0,2)}, {R(1,0), R(1,1), R(1,2)}, {R(2,0), R(2,1), R(2,2)}};
cv::Mat R_mat = cv::Mat(3, 3, CV_64F, m);
cv::Mat K_mat = (cv::Mat_<double>(3,3)<< f,0.0,0.0,0.0,f,0.0,0.0,0.0,1.0);
cv::Mat K_c= K_mat.clone();
K_c=K_c.inv();
cv::Mat C = (cv::Mat_<double>(3,3)<< 1,0,-center.x,0,1,-center.y,0,0,1);
cv::Mat H=K_mat*R_mat*K_c*C;
//Calclating Resultant Translation and Scale
std::vector<Point2f> Ref_c;
std::vector<Point2f> Ref_c_out;
Ref_c.resize(4);
Ref_c_out.resize(4);
Ref_c[0].x=0;
Ref_c[0].y=0;
Ref_c[1].x=double(my_image.width);
Ref_c[1].y=0;
Ref_c[2].x=double(my_image.width);
Ref_c[2].y=double(my_image.height);
Ref_c[3].x=0;
Ref_c[3].y=double(my_image.height);
perspectiveTransform(Ref_c, Ref_c_out, H);
if (talk) cout << "Ref Out New: " << Ref_c_out << endl;
//Scalling:
double scale_fac=abs((max(Ref_c_out[1].x,Ref_c_out[2].x)-min(Ref_c_out[0].x,Ref_c_out[3].x))/my_image.width); //Based on Length
if (talk) cout << "Scale Factor: " << scale_fac << endl;
Ref_c_out[0].x=Ref_c_out[0].x/scale_fac;
Ref_c_out[0].y=Ref_c_out[0].y/scale_fac;
Ref_c_out[1].x=Ref_c_out[1].x/scale_fac;
Ref_c_out[1].y=Ref_c_out[1].y/scale_fac;
Ref_c_out[2].x=Ref_c_out[2].x/scale_fac;
Ref_c_out[2].y=Ref_c_out[2].y/scale_fac;
Ref_c_out[3].x=Ref_c_out[3].x/scale_fac;
Ref_c_out[3].y=Ref_c_out[3].y/scale_fac;
Ref_c_out[1].x=Ref_c_out[1].x-Ref_c_out[0].x;
Ref_c_out[1].y=Ref_c_out[1].y-Ref_c_out[0].y;
Ref_c_out[2].x=Ref_c_out[2].x-Ref_c_out[0].x;
Ref_c_out[2].y=Ref_c_out[2].y-Ref_c_out[0].y;
Ref_c_out[3].x=Ref_c_out[3].x-Ref_c_out[0].x;
Ref_c_out[3].y=Ref_c_out[3].y-Ref_c_out[0].y;
Ref_c_out[0].x=Ref_c_out[0].x-Ref_c_out[0].x;
Ref_c_out[0].y=Ref_c_out[0].y-Ref_c_out[0].y;
if (talk) (cout << "Ref Out New: " << Ref_c_out << endl);
H = getPerspectiveTransform( Ref_c, Ref_c_out ); //For the Translated/Scalled Image
//Applying Homography//
Mat src_img(cv:: Size (my_image.width, my_image.height),CV_8UC3,my_image.getPixels()); //OF to OpenCV
cv::Mat dst_img;
dst_img.create(src_img.size(), src_img.type());
cv::warpPerspective(src_img, dst_img, H, src_img.size(), cv::INTER_LINEAR);
//OpenCV to OF
my_image.setFromPixels((unsigned char *) IplImage(dst_img). imageData,dst_img.size().width, dst_img.size().height,OF_IMAGE_COLOR);
cout << endl <<"Press any key to Save Output Image." << endl;
}