I want to read images from a video camera using OpenCv

Hello, Thank you always.

I am studying oF using technical books.
The code written for that book does not work well again.

I get an error [No matching member function for call to ‘setFromPixels’] in [setFromPixels ()].

ofApp.h:
#pragma once

#include "ofMain.h"
#include "ofxOpenCv.h"

class ofApp : public ofBaseApp{

public:
	void setup();
	void update();
	void draw();

	void keyPressed(int key);
	void keyReleased(int key);
	void mouseMoved(int x, int y );
	void mouseDragged(int x, int y, int button);
	void mousePressed(int x, int y, int button);
	void mouseReleased(int x, int y, int button);
	void mouseEntered(int x, int y);
	void mouseExited(int x, int y);
	void windowResized(int w, int h);
	void dragEvent(ofDragInfo dragInfo);
	void gotMessage(ofMessage msg);

ofVideoGrabber vidGrabber;
ofxCvColorImage colorImg;

};

ofApp.h:
#include "ofApp.h"

//--------------------------------------------------------------
void ofApp::setup(){

ofBackground(0, 0, 0);

vidGrabber.initGrabber(320, 240);

colorImg.allocate(320,240);

}

//--------------------------------------------------------------
void ofApp::update(){

bool bNewFrame = false;
vidGrabber.update();
bNewFrame = vidGrabber.isFrameNew();

if(bNewFrame){
    colorImg.setFromPixels(vidGrabber.getPixels(), 320, 240);
}

}

//--------------------------------------------------------------
void ofApp::draw(){

colorImg.draw(10,10);

}

It is like this

please tell me.

Hi samurai.
The code you are trying to use is out-of-date.
vidGrabber.getPixels() now return a ofPixels object not an unsigned * char.
So, try to use setPixels(vidGrabber.getPixels()) instead setPixels(vidGrabber.getPixels,320,240).

mcollina

Thank you very much.:slight_smile:

We successfully worked with vidGrabber.getPixels () instead of (vidGrabber.getPixels, 320, 240).