Move OpenCVTexture, ARToolKit and WebcamVideo to a new "vision" module

This commit is contained in:
rdb 2009-11-08 12:56:45 +00:00
parent 340aafea67
commit 7036d75501
21 changed files with 154 additions and 59 deletions

View File

@ -1,7 +1,7 @@
#define OTHER_LIBS interrogatedb:c dconfig:c dtoolconfig:m \ #define OTHER_LIBS interrogatedb:c dconfig:c dtoolconfig:m \
dtoolutil:c dtoolbase:c dtool:m prc:c dtoolutil:c dtoolbase:c dtool:m prc:c
#define USE_PACKAGES opencv ffmpeg artoolkit #define USE_PACKAGES ffmpeg
#begin lib_target #begin lib_target
#define TARGET grutil #define TARGET grutil
@ -13,7 +13,6 @@
#define SOURCES \ #define SOURCES \
pipeOcclusionCullTraverser.I pipeOcclusionCullTraverser.h \ pipeOcclusionCullTraverser.I pipeOcclusionCullTraverser.h \
cardMaker.I cardMaker.h \ cardMaker.I cardMaker.h \
arToolKit.I arToolKit.h \
config_grutil.h \ config_grutil.h \
ffmpegTexture.I ffmpegTexture.h \ ffmpegTexture.I ffmpegTexture.h \
movieTexture.I movieTexture.h \ movieTexture.I movieTexture.h \
@ -26,12 +25,10 @@
lineSegs.I lineSegs.h \ lineSegs.I lineSegs.h \
multitexReducer.I multitexReducer.h multitexReducer.cxx \ multitexReducer.I multitexReducer.h multitexReducer.cxx \
nodeVertexTransform.I nodeVertexTransform.h \ nodeVertexTransform.I nodeVertexTransform.h \
openCVTexture.I openCVTexture.h \
rigidBodyCombiner.I rigidBodyCombiner.h rigidBodyCombiner.I rigidBodyCombiner.h
#define INCLUDED_SOURCES \ #define INCLUDED_SOURCES \
cardMaker.cxx \ cardMaker.cxx \
arToolKit.cxx \
ffmpegTexture.cxx \ ffmpegTexture.cxx \
movieTexture.cxx \ movieTexture.cxx \
fisheyeMaker.cxx \ fisheyeMaker.cxx \
@ -42,14 +39,12 @@
sceneGraphAnalyzerMeter.cxx \ sceneGraphAnalyzerMeter.cxx \
heightfieldTesselator.cxx \ heightfieldTesselator.cxx \
nodeVertexTransform.cxx \ nodeVertexTransform.cxx \
openCVTexture.cxx \
pipeOcclusionCullTraverser.cxx \ pipeOcclusionCullTraverser.cxx \
lineSegs.cxx \ lineSegs.cxx \
rigidBodyCombiner.cxx rigidBodyCombiner.cxx
#define INSTALL_HEADERS \ #define INSTALL_HEADERS \
cardMaker.I cardMaker.h \ cardMaker.I cardMaker.h \
arToolKit.I arToolKit.h \
ffmpegTexture.I ffmpegTexture.h \ ffmpegTexture.I ffmpegTexture.h \
movieTexture.I movieTexture.h \ movieTexture.I movieTexture.h \
fisheyeMaker.I fisheyeMaker.h \ fisheyeMaker.I fisheyeMaker.h \
@ -61,7 +56,6 @@
lineSegs.I lineSegs.h \ lineSegs.I lineSegs.h \
multitexReducer.I multitexReducer.h \ multitexReducer.I multitexReducer.h \
nodeVertexTransform.I nodeVertexTransform.h \ nodeVertexTransform.I nodeVertexTransform.h \
openCVTexture.I openCVTexture.h \
rigidBodyCombiner.I rigidBodyCombiner.h rigidBodyCombiner.I rigidBodyCombiner.h
#define IGATESCAN all #define IGATESCAN all

View File

@ -17,7 +17,6 @@
#include "sceneGraphAnalyzerMeter.h" #include "sceneGraphAnalyzerMeter.h"
#include "meshDrawer.h" #include "meshDrawer.h"
#include "geoMipTerrain.h" #include "geoMipTerrain.h"
#include "openCVTexture.h"
#include "ffmpegTexture.h" #include "ffmpegTexture.h"
#include "movieTexture.h" #include "movieTexture.h"
#include "pandaSystem.h" #include "pandaSystem.h"
@ -98,34 +97,20 @@ init_libgrutil() {
MovieTexture::init_type(); MovieTexture::init_type();
MovieTexture::register_with_read_factory(); MovieTexture::register_with_read_factory();
#endif // HAVE_AUDIO #endif // HAVE_AUDIO
#ifdef HAVE_OPENCV
OpenCVTexture::init_type();
OpenCVTexture::register_with_read_factory();
#endif
#ifdef HAVE_FFMPEG #ifdef HAVE_FFMPEG
av_register_all(); av_register_all();
FFMpegTexture::init_type(); FFMpegTexture::init_type();
FFMpegTexture::register_with_read_factory(); FFMpegTexture::register_with_read_factory();
#endif #endif
#ifdef HAVE_OPENCV #if defined(HAVE_FFMPEG)
PandaSystem *ps = PandaSystem::get_global_ptr();
ps->add_system("OpenCV");
#endif
TexturePool *ts = TexturePool::get_global_ptr(); TexturePool *ts = TexturePool::get_global_ptr();
if (use_movietexture) { if (use_movietexture) {
#if defined(HAVE_FFMPEG)
ts->register_texture_type(MovieTexture::make_texture, "avi mov mpg wmv asf flv nut ogm"); ts->register_texture_type(MovieTexture::make_texture, "avi mov mpg wmv asf flv nut ogm");
#elif defined(HAVE_OPENCV)
ts->register_texture_type(OpenCVTexture::make_texture, "avi");
#endif
} else { } else {
#if defined(HAVE_FFMPEG)
ts->register_texture_type(FFMpegTexture::make_texture, "avi mov mpg wmv asf flv nut ogm"); ts->register_texture_type(FFMpegTexture::make_texture, "avi mov mpg wmv asf flv nut ogm");
#elif defined(HAVE_OPENCV)
ts->register_texture_type(OpenCVTexture::make_texture, "avi");
#endif
} }
#endif
} }

View File

@ -1,5 +1,4 @@
#include "cardMaker.cxx" #include "cardMaker.cxx"
#include "arToolKit.cxx"
#include "heightfieldTesselator.cxx" #include "heightfieldTesselator.cxx"
#include "geoMipTerrain.cxx" #include "geoMipTerrain.cxx"
#include "config_grutil.cxx" #include "config_grutil.cxx"

View File

@ -1,4 +1,3 @@
#include "openCVTexture.cxx"
#include "ffmpegTexture.cxx" #include "ffmpegTexture.cxx"
#include "movieTexture.cxx" #include "movieTexture.cxx"
#include "nodeVertexTransform.cxx" #include "nodeVertexTransform.cxx"

View File

@ -25,7 +25,6 @@
ffmpegVirtualFile.h ffmpegVirtualFile.I \ ffmpegVirtualFile.h ffmpegVirtualFile.I \
userDataAudio.h userDataAudio.I \ userDataAudio.h userDataAudio.I \
userDataAudioCursor.h userDataAudioCursor.I \ userDataAudioCursor.h userDataAudioCursor.I \
webcamVideo.h webcamVideo.I \
microphoneAudio.h microphoneAudio.I \ microphoneAudio.h microphoneAudio.I \
config_movies.h config_movies.h
@ -43,8 +42,6 @@
ffmpegVirtualFile.cxx \ ffmpegVirtualFile.cxx \
userDataAudio.cxx \ userDataAudio.cxx \
userDataAudioCursor.cxx \ userDataAudioCursor.cxx \
webcamVideo.cxx \
webcamVideoDS.cxx \
microphoneAudio.cxx \ microphoneAudio.cxx \
microphoneAudioDS.cxx \ microphoneAudioDS.cxx \
config_movies.cxx config_movies.cxx
@ -61,7 +58,6 @@
ffmpegAudio.h ffmpegAudio.I \ ffmpegAudio.h ffmpegAudio.I \
ffmpegAudioCursor.h ffmpegAudioCursor.I \ ffmpegAudioCursor.h ffmpegAudioCursor.I \
ffmpegVirtualFile.h ffmpegVirtualFile.I \ ffmpegVirtualFile.h ffmpegVirtualFile.I \
webcamVideo.h webcamVideo.I \
microphoneAudio.h microphoneAudio.I \ microphoneAudio.h microphoneAudio.I \
config_movies.h config_movies.h

View File

@ -14,7 +14,6 @@
#include "config_movies.h" #include "config_movies.h"
#include "dconfig.h" #include "dconfig.h"
#include "webcamVideo.h"
#ifdef HAVE_FFMPEG #ifdef HAVE_FFMPEG
extern "C" { extern "C" {
@ -53,7 +52,6 @@ init_libmovies() {
InkblotVideoCursor::init_type(); InkblotVideoCursor::init_type();
UserDataAudio::init_type(); UserDataAudio::init_type();
UserDataAudioCursor::init_type(); UserDataAudioCursor::init_type();
WebcamVideo::init_type();
MicrophoneAudio::init_type(); MicrophoneAudio::init_type();
#ifdef HAVE_FFMPEG #ifdef HAVE_FFMPEG
FfmpegVideo::init_type(); FfmpegVideo::init_type();

View File

@ -18,9 +18,6 @@
#include "userDataAudio.cxx" #include "userDataAudio.cxx"
#include "userDataAudioCursor.cxx" #include "userDataAudioCursor.cxx"
#include "webcamVideo.cxx"
#include "webcamVideoDS.cxx"
#include "microphoneAudio.cxx" #include "microphoneAudio.cxx"
#include "microphoneAudioDS.cxx" #include "microphoneAudioDS.cxx"

View File

@ -0,0 +1,34 @@
#define OTHER_LIBS interrogatedb:c dconfig:c dtoolconfig:m \
dtoolutil:c dtoolbase:c dtool:m prc:c movies:m
#define USE_PACKAGES opencv artoolkit
#begin lib_target
#define TARGET vision
#define LOCAL_LIBS \
display text pgraph gobj linmath putil movies audio
#define COMBINED_SOURCES $[TARGET]_composite1.cxx
#define SOURCES \
arToolKit.I arToolKit.h \
config_vision.h \
openCVTexture.I openCVTexture.h \
webcamVideo.h webcamVideo.I
#define INCLUDED_SOURCES \
arToolKit.cxx \
config_vision.cxx \
openCVTexture.cxx \
webcamVideo.cxx \
webcamVideoDS.cxx
#define INSTALL_HEADERS \
arToolKit.I arToolKit.h \
openCVTexture.I openCVTexture.h \
webcamVideo.h webcamVideo.I
#define IGATESCAN all
#end lib_target

View File

@ -21,7 +21,7 @@
#include "perspectiveLens.h" #include "perspectiveLens.h"
#include "lvecBase3.h" #include "lvecBase3.h"
#include "compose_matrix.h" #include "compose_matrix.h"
#include "config_grutil.h" #include "config_vision.h"
extern "C" { extern "C" {
#include "AR/ar.h" #include "AR/ar.h"
}; };
@ -123,7 +123,7 @@ make(NodePath camera, const Filename &paramfile, double marker_size) {
AR_DEFAULT_PIXEL_FORMAT != AR_PIXEL_FORMAT_RGBA && AR_DEFAULT_PIXEL_FORMAT != AR_PIXEL_FORMAT_RGBA &&
AR_DEFAULT_PIXEL_FORMAT != AR_PIXEL_FORMAT_RGB && AR_DEFAULT_PIXEL_FORMAT != AR_PIXEL_FORMAT_RGB &&
AR_DEFAULT_PIXEL_FORMAT != AR_PIXEL_FORMAT_BGR) { AR_DEFAULT_PIXEL_FORMAT != AR_PIXEL_FORMAT_BGR) {
grutil_cat.error() << vision_cat.error() <<
"The copy of ARToolKit that you are using is not compiled " "The copy of ARToolKit that you are using is not compiled "
"for RGB, BGR, RGBA or ARGB input. Panda3D cannot use " "for RGB, BGR, RGBA or ARGB input. Panda3D cannot use "
"this copy of ARToolKit. Please modify the ARToolKit's " "this copy of ARToolKit. Please modify the ARToolKit's "
@ -132,25 +132,25 @@ make(NodePath camera, const Filename &paramfile, double marker_size) {
} }
if (camera.is_empty()) { if (camera.is_empty()) {
grutil_cat.error() << "ARToolKit: invalid camera nodepath\n"; vision_cat.error() << "ARToolKit: invalid camera nodepath\n";
return 0; return 0;
} }
PandaNode *node = camera.node(); PandaNode *node = camera.node();
if ((node == 0) || (node->get_type() != Camera::get_class_type())) { if ((node == 0) || (node->get_type() != Camera::get_class_type())) {
grutil_cat.error() << "ARToolKit: invalid camera nodepath\n"; vision_cat.error() << "ARToolKit: invalid camera nodepath\n";
return 0; return 0;
} }
Camera *cam = DCAST(Camera, node); Camera *cam = DCAST(Camera, node);
Lens *lens = cam->get_lens(); Lens *lens = cam->get_lens();
if (lens->get_type() != PerspectiveLens::get_class_type()) { if (lens->get_type() != PerspectiveLens::get_class_type()) {
grutil_cat.error() << "ARToolKit: supplied camera node must be perspective.\n"; vision_cat.error() << "ARToolKit: supplied camera node must be perspective.\n";
return 0; return 0;
} }
ARParam wparam; ARParam wparam;
string fn = paramfile.to_os_specific(); string fn = paramfile.to_os_specific();
if( arParamLoad(fn.c_str(), 1, &wparam) < 0 ) { if( arParamLoad(fn.c_str(), 1, &wparam) < 0 ) {
grutil_cat.error() << "Cannot load ARToolKit camera config\n"; vision_cat.error() << "Cannot load ARToolKit camera config\n";
return 0; return 0;
} }
@ -221,7 +221,7 @@ get_pattern(const Filename &filename) {
string fn = filename.to_os_specific(); string fn = filename.to_os_specific();
int id = arLoadPatt(fn.c_str()); int id = arLoadPatt(fn.c_str());
if (id < 0) { if (id < 0) {
grutil_cat.error() << "Could not load AR ToolKit Pattern: " << fn << "\n"; vision_cat.error() << "Could not load AR ToolKit Pattern: " << fn << "\n";
return -1; return -1;
} }
arDeactivatePatt(id); arDeactivatePatt(id);
@ -275,7 +275,7 @@ analyze(Texture *tex, bool do_flip_texture) {
nassertv(tex->get_texture_type() == Texture::TT_2d_texture); nassertv(tex->get_texture_type() == Texture::TT_2d_texture);
if (tex->get_num_components() != 3 && tex->get_num_components() != 4) { if (tex->get_num_components() != 3 && tex->get_num_components() != 4) {
grutil_cat.error() << "ARToolKit can only analyze RGB and RGBA textures.\n"; vision_cat.error() << "ARToolKit can only analyze RGB and RGBA textures.\n";
return; return;
} }
@ -381,7 +381,7 @@ analyze(Texture *tex, bool do_flip_texture) {
int marker_num; int marker_num;
if (arDetectMarker(data, _threshold * 256, &marker_info, &marker_num) < 0) { if (arDetectMarker(data, _threshold * 256, &marker_info, &marker_num) < 0) {
grutil_cat.error() << "ARToolKit detection error.\n"; vision_cat.error() << "ARToolKit detection error.\n";
delete data; delete data;
return; return;
} }
@ -423,7 +423,7 @@ analyze(Texture *tex, bool do_flip_texture) {
decompose_matrix(mat, scale, shear, hpr, pos); decompose_matrix(mat, scale, shear, hpr, pos);
if (np.get_parent().is_empty()) { if (np.get_parent().is_empty()) {
grutil_cat.error() << "NodePath must have a parent.\n"; vision_cat.error() << "NodePath must have a parent.\n";
} else { } else {
np.set_pos_hpr(_camera, pos, hpr); np.set_pos_hpr(_camera, pos, hpr);
} }

View File

@ -40,7 +40,7 @@
// This class is a wrapper around the ARToolKit // This class is a wrapper around the ARToolKit
// library. // library.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
class EXPCL_PANDA_GRUTIL ARToolKit { class EXPCL_VISION ARToolKit {
PUBLISHED: PUBLISHED:
static ARToolKit *make(NodePath camera, const Filename &paramfile, double markersize); static ARToolKit *make(NodePath camera, const Filename &paramfile, double markersize);

View File

@ -0,0 +1,61 @@
// Filename: config_vision.cxx
// Created by: pro-rsoft (07Nov09)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) Carnegie Mellon University. All rights reserved.
//
// All use of this software is subject to the terms of the revised BSD
// license. You should have received a copy of this license along
// with this source code in a file named "LICENSE."
//
////////////////////////////////////////////////////////////////////
#include "config_vision.h"
#include "openCVTexture.h"
#include "webcamVideo.h"
#include "pandaSystem.h"
#include "texturePool.h"
#include "dconfig.h"
Configure(config_vision);
NotifyCategoryDef(vision, "");
ConfigureFn(config_vision) {
init_libvision();
}
////////////////////////////////////////////////////////////////////
// Function: init_libvision
// Description: Initializes the library. This must be called at
// least once before any of the functions or classes in
// this library can be used. Normally it will be
// called by the static initializers and need not be
// called explicitly, but special cases exist.
////////////////////////////////////////////////////////////////////
void
init_libvision() {
static bool initialized = false;
if (initialized) {
return;
}
initialized = true;
WebcamVideo::init_type();
#ifdef HAVE_OPENCV
OpenCVTexture::init_type();
OpenCVTexture::register_with_read_factory();
PandaSystem *ps = PandaSystem::get_global_ptr();
ps->add_system("OpenCV");
TexturePool *ts = TexturePool::get_global_ptr();
#ifndef HAVE_FFMPEG
ts->register_texture_type(OpenCVTexture::make_texture, "avi");
#endif
#endif
}

View File

@ -0,0 +1,26 @@
// Filename: config_vision.h
// Created by: pro-rsoft (07Nov09)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) Carnegie Mellon University. All rights reserved.
//
// All use of this software is subject to the terms of the revised BSD
// license. You should have received a copy of this license along
// with this source code in a file named "LICENSE."
//
////////////////////////////////////////////////////////////////////
#ifndef CONFIG_VISION_H
#define CONFIG_VISION_H
#include "pandabase.h"
#include "notifyCategoryProxy.h"
NotifyCategoryDecl(vision, EXPCL_VISION, EXPTP_VISION);
extern EXPCL_VISION void init_libvision();
#endif

View File

@ -18,7 +18,7 @@
#include "openCVTexture.h" #include "openCVTexture.h"
#include "clockObject.h" #include "clockObject.h"
#include "config_gobj.h" #include "config_gobj.h"
#include "config_grutil.h" #include "config_vision.h"
#include "bamReader.h" #include "bamReader.h"
#include "bamCacheRecord.h" #include "bamCacheRecord.h"
@ -156,8 +156,8 @@ do_reconsider_video_properties(const OpenCVTexture::VideoStream &stream,
if (stream.is_from_file()) { if (stream.is_from_file()) {
frame_rate = cvGetCaptureProperty(stream._capture, CV_CAP_PROP_FPS); frame_rate = cvGetCaptureProperty(stream._capture, CV_CAP_PROP_FPS);
num_frames = (int)cvGetCaptureProperty(stream._capture, CV_CAP_PROP_FRAME_COUNT); num_frames = (int)cvGetCaptureProperty(stream._capture, CV_CAP_PROP_FRAME_COUNT);
if (grutil_cat.is_debug()) { if (vision_cat.is_debug()) {
grutil_cat.debug() vision_cat.debug()
<< "Loaded " << stream._filename << ", " << num_frames << " frames at " << "Loaded " << stream._filename << ", " << num_frames << " frames at "
<< frame_rate << " fps\n"; << frame_rate << " fps\n";
} }
@ -173,8 +173,8 @@ do_reconsider_video_properties(const OpenCVTexture::VideoStream &stream,
y_size = up_to_power_2(height); y_size = up_to_power_2(height);
} }
if (grutil_cat.is_debug()) { if (vision_cat.is_debug()) {
grutil_cat.debug() vision_cat.debug()
<< "Video stream is " << width << " by " << height << "Video stream is " << width << " by " << height
<< " pixels; fitting in texture " << x_size << " by " << " pixels; fitting in texture " << x_size << " by "
<< y_size << " texels.\n"; << y_size << " texels.\n";
@ -188,7 +188,7 @@ do_reconsider_video_properties(const OpenCVTexture::VideoStream &stream,
if (_loaded_from_image && if (_loaded_from_image &&
(get_video_width() != width || get_video_height() != height || (get_video_width() != width || get_video_height() != height ||
get_num_frames() != num_frames || get_frame_rate() != frame_rate)) { get_num_frames() != num_frames || get_frame_rate() != frame_rate)) {
grutil_cat.error() vision_cat.error()
<< "Video properties have changed for texture " << get_name() << "Video properties have changed for texture " << get_name()
<< " level " << z << ".\n"; << " level " << z << ".\n";
return false; return false;
@ -238,7 +238,7 @@ update_frame(int frame) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void OpenCVTexture:: void OpenCVTexture::
update_frame(int frame, int z) { update_frame(int frame, int z) {
grutil_cat.spam() << "Updating OpenCVTexture page " << z << "\n"; vision_cat.spam() << "Updating OpenCVTexture page " << z << "\n";
VideoPage &page = _pages[z]; VideoPage &page = _pages[z];
if (page._color.is_valid() || page._alpha.is_valid()) { if (page._color.is_valid() || page._alpha.is_valid()) {
do_modify_ram_image(); do_modify_ram_image();
@ -332,13 +332,13 @@ do_read_one(const Filename &fullpath, const Filename &alpha_fullpath,
VideoPage &page = modify_page(z); VideoPage &page = modify_page(z);
if (!page._color.read(fullpath)) { if (!page._color.read(fullpath)) {
grutil_cat.error() vision_cat.error()
<< "OpenCV couldn't read " << fullpath << " as video.\n"; << "OpenCV couldn't read " << fullpath << " as video.\n";
return false; return false;
} }
if (!alpha_fullpath.empty()) { if (!alpha_fullpath.empty()) {
if (!page._alpha.read(alpha_fullpath)) { if (!page._alpha.read(alpha_fullpath)) {
grutil_cat.error() vision_cat.error()
<< "OpenCV couldn't read " << alpha_fullpath << " as video.\n"; << "OpenCV couldn't read " << alpha_fullpath << " as video.\n";
page._color.clear(); page._color.clear();
return false; return false;

View File

@ -31,7 +31,7 @@
// with its source taken from an .avi file or from a // with its source taken from an .avi file or from a
// camera input. // camera input.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
class EXPCL_PANDA_GRUTIL OpenCVTexture : public VideoTexture { class EXPCL_VISION OpenCVTexture : public VideoTexture {
PUBLISHED: PUBLISHED:
OpenCVTexture(const string &name = string()); OpenCVTexture(const string &name = string());
protected: protected:

View File

@ -0,0 +1,6 @@
#include "arToolKit.cxx"
#include "config_vision.cxx"
#include "openCVTexture.cxx"
#include "webcamVideo.cxx"
#include "webcamVideoDS.cxx"

View File

@ -22,7 +22,7 @@
// Description : Allows you to open a webcam or other video capture // Description : Allows you to open a webcam or other video capture
// device as a video stream. // device as a video stream.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
class EXPCL_PANDA_MOVIES WebcamVideo : public MovieVideo { class EXPCL_VISION WebcamVideo : public MovieVideo {
PUBLISHED: PUBLISHED:
virtual ~WebcamVideo(); virtual ~WebcamVideo();