I’ve been trying to use a webcam in C++… so far unsucessfully
My config is Windows 7. I have opencv installed and the directshow webcam working ok (out of Panda).
I see that there are two possibly interesting webcamVideo derived classes:
webcamVideoOpenCV and webcamVideoDS
So the question is how to include them in a Panda C++ code?
Thanks for some guidance
rdb
April 11, 2011, 8:24am
2
Same as in Python, and similarly as how MicrophoneAudio works. Just include webcamVideo.h and get an option using WebcamVideo::get_num_options()/get_option().
Ok, I obviously tried it but this is where I stand … and stuck !
#include "videoTexture.h"
#include "movieVideoCursor.h"
#include "movieTexture.h"
#include "webcamVideo.h"
...
num_options = WebcamVideo::get_num_options();
for (int m=0; m<num_options; m++) {
std::cout << "webcam option " << m << " " << WebcamVideo::get_option(m)->get_name() << "\n";
}
PT(WebcamVideo) webcam = WebcamVideo::get_option(0);
PT(MovieVideoCursor) camcur = webcam->open();
assert(camcur->streaming());
std::cout << "cam image: size_x: " << camcur->size_x() << " size_y: " << camcur->size_y() << "\n";
The webcam opens ok, however then the issue is how to grab the texture?
Should a VideoTexture be used or a MovieTexture, I’m really confused!
PT(MovieTexture) mycamTexture;
camcur->setup_texture(mycamTexture);
or something like ??????
PT(MovieTexture) mycamTexture = new MovieTexture(DCAST(MovieVideo,webcam));
myObject.set_texture(mycamTexture);
and possibly be able to work on the texture buffer with openCV?
if (camcur->ready()) {
... process image buffer prior to displaying it
}
rdb
April 11, 2011, 1:51pm
4
Use a MovieTexture. and use set_texture. There are many examples on the forums about this.
I’m really sorry to insist and ask for guidance (as a dumb guy), but I did try and look at relevant examples (actually there are not so many involving a webcam), and I’m still stuck with :
num_options = WebcamVideo::get_num_options();
for (int m=0; m<num_options; m++) {
std::cout << "webcam option " << m << " " << WebcamVideo::get_option(m)->get_name() << "\n";
}
PT(WebcamVideo) webcam = WebcamVideo::get_option(0);
PT(MovieVideoCursor) camcur = webcam->open();
PT(MovieTexture) mycamTexture = new MovieTexture(DCAST(MovieVideo,webcam));
mycamTexture->play();
CardMaker cmtw("movie_texture");
cmtw.set_frame(-160, 160, -120, 120);
NodePath moview = render.attach_new_node(cmtw.generate());
moview.set_pos(-200, 450, 200);
moview.set_texture(mycamTexture);
There is no video displayed on the card!!!
I must be missing something…
There is definitively something wrong with WebcamVideo on Windows… This is the kind of weird result I’m getting.
WebcamVideo::find_all_webcams();
num_options = WebcamVideo::get_num_options();
std::cout << "num_options: " << num_options << "\n";
for (int m=0; m<num_options; m++) {
PT(WebcamVideo) webcam_m = WebcamVideo::get_option(m);
std::cout << "webcam option " << m << " " << webcam_m->get_name()
<< " sizeX: " << webcam_m->get_size_x()
<< " sizeY: " << webcam_m->get_size_y()
<< " fps: " << webcam_m->get_fps() << "\n";
}
PT(WebcamVideo) webcam = WebcamVideo::get_option(0);
PT(MovieVideoCursor) camcur = webcam->open();
assert(camcur->streaming());
std::cout <<"cam image: size_x: "<< camcur->size_x() <<" size_y: "<< camcur->size_y() <<"\n";
So, this is the output…
num_options: 1
webcam option 0 OpenCV webcam 0 sizeX: 169150997 sizeY: 174525033 fps: 174918130
cam image: size_x: 169150997 size_y: 174525033
The reported size are completely crazy!!
Help really needed!!!