From ecf6b5a87c095510ec90279d629a9bebf06993ac Mon Sep 17 00:00:00 2001 From: Andrey Kamaev Date: Tue, 26 Jun 2012 07:29:36 +0000 Subject: [PATCH] Making all dependencies from highgui module optional --- modules/contrib/CMakeLists.txt | 2 +- modules/contrib/src/chamfermatching.cpp | 10 ++- modules/contrib/src/rgbdodometry.cpp | 9 ++- modules/legacy/CMakeLists.txt | 2 +- modules/legacy/src/image.cpp | 25 +++++++- modules/legacy/src/oneway.cpp | 16 ++++- modules/objdetect/CMakeLists.txt | 2 +- modules/videostab/CMakeLists.txt | 2 +- .../opencv2/videostab/frame_source.hpp | 13 ++-- modules/videostab/src/frame_source.cpp | 64 +++++++++++++++++-- modules/videostab/src/precomp.hpp | 1 - samples/cpp/dbt_face_detection.cpp | 2 +- 12 files changed, 124 insertions(+), 24 deletions(-) diff --git a/modules/contrib/CMakeLists.txt b/modules/contrib/CMakeLists.txt index 2c338b8f4f..81c9ea4aa5 100644 --- a/modules/contrib/CMakeLists.txt +++ b/modules/contrib/CMakeLists.txt @@ -1 +1 @@ -ocv_define_module(contrib opencv_imgproc opencv_calib3d opencv_features2d opencv_highgui opencv_ml opencv_video opencv_objdetect) +ocv_define_module(contrib opencv_imgproc opencv_calib3d opencv_features2d opencv_ml opencv_video opencv_objdetect OPTIONAL opencv_highgui) diff --git a/modules/contrib/src/chamfermatching.cpp b/modules/contrib/src/chamfermatching.cpp index 42fcd29ad6..09d589e5db 100644 --- a/modules/contrib/src/chamfermatching.cpp +++ b/modules/contrib/src/chamfermatching.cpp @@ -44,7 +44,10 @@ // #include "precomp.hpp" -#include "opencv2/highgui/highgui.hpp" +#include "opencv2/opencv_modules.hpp" +#ifdef HAVE_OPENCV_HIGHGUI +# include "opencv2/highgui/highgui.hpp" +#endif #include #include @@ -907,13 +910,16 @@ void ChamferMatcher::Template::show() const } } - circle(templ_color,Point(center.x + pad, center.y + pad),1,CV_RGB(0,255,0)); +#ifdef HAVE_OPENCV_HIGHGUI namedWindow("templ",1); imshow("templ",templ_color); cvWaitKey(0); +#else + CV_Error(CV_StsNotImplemented, "OpenCV has been compiled without GUI support"); +#endif templ_color.release(); } diff --git a/modules/contrib/src/rgbdodometry.cpp b/modules/contrib/src/rgbdodometry.cpp index 59f3254022..0ea8d18b4c 100644 --- a/modules/contrib/src/rgbdodometry.cpp +++ b/modules/contrib/src/rgbdodometry.cpp @@ -39,10 +39,16 @@ // the use of this software, even if advised of the possibility of such damage. // //M*/ + +#define SHOW_DEBUG_IMAGES 0 + #include "opencv2/core/core.hpp" #include "opencv2/calib3d/calib3d.hpp" -#include "opencv2/highgui/highgui.hpp" +#if SHOW_DEBUG_IMAGES +# include "opencv2/highgui/highgui.hpp" +#endif + #include "precomp.hpp" #include @@ -58,7 +64,6 @@ #include -#define SHOW_DEBUG_IMAGES 0 using namespace cv; inline static diff --git a/modules/legacy/CMakeLists.txt b/modules/legacy/CMakeLists.txt index 960071080c..348de72853 100644 --- a/modules/legacy/CMakeLists.txt +++ b/modules/legacy/CMakeLists.txt @@ -1 +1 @@ -ocv_define_module(legacy opencv_calib3d opencv_highgui opencv_video opencv_ml) +ocv_define_module(legacy opencv_calib3d opencv_video opencv_ml OPTIONAL opencv_highgui) diff --git a/modules/legacy/src/image.cpp b/modules/legacy/src/image.cpp index 729cd6c6a7..3f691bc27f 100644 --- a/modules/legacy/src/image.cpp +++ b/modules/legacy/src/image.cpp @@ -46,7 +46,10 @@ // */ #include "precomp.hpp" -#include "opencv2/highgui/highgui_c.h" +#include "opencv2/opencv_modules.hpp" +#ifdef HAVE_OPENCV_HIGHGUI +# include "opencv2/highgui/highgui_c.h" +#endif /////////////////////////////// CvImage implementation ////////////////////////////////// @@ -112,8 +115,10 @@ bool CvImage::load( const char* filename, const char* imgname, int color ) img = temp_img; }*/ } +#ifdef HAVE_OPENCV_HIGHGUI else img = cvLoadImage( filename, color ); +#endif attach( img ); return img != 0; @@ -161,8 +166,12 @@ void CvImage::save( const char* filename, const char* imgname, const int* params return; if( icvIsXmlOrYaml( filename ) ) cvSave( filename, image, imgname ); +#ifdef HAVE_OPENCV_HIGHGUI else cvSaveImage( filename, image, params ); +#else + (void)params; +#endif } @@ -175,8 +184,12 @@ void CvImage::write( CvFileStorage* fs, const char* imgname ) void CvImage::show( const char* window_name ) { +#ifdef HAVE_OPENCV_HIGHGUI if( image ) cvShowImage( window_name, image ); +#else + (void)window_name; +#endif } @@ -238,8 +251,10 @@ bool CvMatrix::load( const char* filename, const char* matname, int color ) m = temp_mat; }*/ } +#ifdef HAVE_OPENCV_HIGHGUI else m = cvLoadImageM( filename, color ); +#endif set( m, false ); return m != 0; @@ -287,8 +302,12 @@ void CvMatrix::save( const char* filename, const char* matname, const int* param return; if( icvIsXmlOrYaml( filename ) ) cvSave( filename, matrix, matname ); +#ifdef HAVE_OPENCV_HIGHGUI else cvSaveImage( filename, matrix, params ); +#else + (void)params; +#endif } @@ -301,8 +320,12 @@ void CvMatrix::write( CvFileStorage* fs, const char* matname ) void CvMatrix::show( const char* window_name ) { +#ifdef HAVE_OPENCV_HIGHGUI if( matrix ) cvShowImage( window_name, matrix ); +#else + (void)window_name; +#endif } diff --git a/modules/legacy/src/oneway.cpp b/modules/legacy/src/oneway.cpp index 3e5b445eec..c758f4c5e8 100644 --- a/modules/legacy/src/oneway.cpp +++ b/modules/legacy/src/oneway.cpp @@ -8,7 +8,10 @@ */ #include "precomp.hpp" -#include "opencv2/highgui/highgui.hpp" +#include "opencv2/opencv_modules.hpp" +#ifdef HAVE_OPENCV_HIGHGUI +# include "opencv2/highgui/highgui.hpp" +#endif #include namespace cv{ @@ -665,7 +668,11 @@ namespace cv{ cvMinMaxLoc(m_samples[i], 0, &maxval); cvConvertScale(m_samples[i], patch, 255/maxval); +#ifdef HAVE_OPENCV_HIGHGUI cvSaveImage(buf, patch); +#else + CV_Error(CV_StsNotImplemented, "OpenCV has been compiled without image I/O support"); +#endif cvReleaseImage(&patch); } @@ -1794,7 +1801,12 @@ namespace cv{ sprintf(filename, "%s/%s", path, imagename); //printf("Reading image %s...", filename); - IplImage* img = cvLoadImage(filename, CV_LOAD_IMAGE_GRAYSCALE); + IplImage* img = 0; +#ifdef HAVE_OPENCV_HIGHGUI + img = cvLoadImage(filename, CV_LOAD_IMAGE_GRAYSCALE); +#else + CV_Error(CV_StsNotImplemented, "OpenCV has been compiled without image I/O support"); +#endif //printf("done\n"); extractPatches (img, patches, patch_size); diff --git a/modules/objdetect/CMakeLists.txt b/modules/objdetect/CMakeLists.txt index ec9419aafe..78aa4aa234 100644 --- a/modules/objdetect/CMakeLists.txt +++ b/modules/objdetect/CMakeLists.txt @@ -1,2 +1,2 @@ set(the_description "Object Detection") -ocv_define_module(objdetect OPTIONAL opencv_highgui) +ocv_define_module(objdetect opencv_core opencv_imgproc OPTIONAL opencv_highgui) diff --git a/modules/videostab/CMakeLists.txt b/modules/videostab/CMakeLists.txt index 443b70b508..edde3f86dd 100644 --- a/modules/videostab/CMakeLists.txt +++ b/modules/videostab/CMakeLists.txt @@ -1,3 +1,3 @@ set(the_description "Video stabilization") -ocv_define_module(videostab opencv_imgproc opencv_features2d opencv_video opencv_highgui opencv_photo opencv_calib3d OPTIONAL opencv_gpu) +ocv_define_module(videostab opencv_imgproc opencv_features2d opencv_video opencv_photo opencv_calib3d OPTIONAL opencv_gpu opencv_highgui) diff --git a/modules/videostab/include/opencv2/videostab/frame_source.hpp b/modules/videostab/include/opencv2/videostab/frame_source.hpp index 3ecf6c6e40..c68dfbf185 100644 --- a/modules/videostab/include/opencv2/videostab/frame_source.hpp +++ b/modules/videostab/include/opencv2/videostab/frame_source.hpp @@ -46,7 +46,6 @@ #include #include #include "opencv2/core/core.hpp" -#include "opencv2/highgui/highgui.hpp" namespace cv { @@ -76,15 +75,17 @@ public: virtual void reset(); virtual Mat nextFrame(); - int width() { return static_cast(reader_.get(CV_CAP_PROP_FRAME_WIDTH)); } - int height() { return static_cast(reader_.get(CV_CAP_PROP_FRAME_HEIGHT)); } - int count() { return static_cast(reader_.get(CV_CAP_PROP_FRAME_COUNT)); } - double fps() { return reader_.get(CV_CAP_PROP_FPS); } + int width(); + int height(); + int count(); + double fps(); private: std::string path_; bool volatileFrame_; - VideoCapture reader_; + + struct VideoReader; + const VideoReader& reader_; }; } // namespace videostab diff --git a/modules/videostab/src/frame_source.cpp b/modules/videostab/src/frame_source.cpp index 4d6a30ee20..72e0570406 100644 --- a/modules/videostab/src/frame_source.cpp +++ b/modules/videostab/src/frame_source.cpp @@ -44,6 +44,11 @@ #include "opencv2/videostab/frame_source.hpp" #include "opencv2/videostab/ring_buffer.hpp" +#include "opencv2/opencv_modules.hpp" +#ifdef HAVE_OPENCV_HIGHGUI +# include "opencv2/highgui/highgui.hpp" +#endif + using namespace std; namespace cv @@ -51,25 +56,74 @@ namespace cv namespace videostab { +struct VideoFileSource::VideoReader +{ +#ifdef HAVE_OPENCV_HIGHGUI + mutable VideoCapture vc; +#endif +}; + VideoFileSource::VideoFileSource(const string &path, bool volatileFrame) - : path_(path), volatileFrame_(volatileFrame) { reset(); } + : path_(path), volatileFrame_(volatileFrame), reader_(VideoReader()) { reset(); } void VideoFileSource::reset() { - reader_.release(); - reader_.open(path_); - if (!reader_.isOpened()) +#ifdef HAVE_OPENCV_HIGHGUI + reader_.vc.release(); + reader_.vc.open(path_); + if (!reader_.vc.isOpened()) throw runtime_error("can't open file: " + path_); +#else + CV_Error(CV_StsNotImplemented, "OpenCV has been compiled without video I/O support"); +#endif } Mat VideoFileSource::nextFrame() { Mat frame; - reader_ >> frame; +#ifdef HAVE_OPENCV_HIGHGUI + reader_.vc >> frame; +#endif return volatileFrame_ ? frame : frame.clone(); } +int VideoFileSource::width() +{ +#ifdef HAVE_OPENCV_HIGHGUI + return static_cast(reader_.vc.get(CV_CAP_PROP_FRAME_WIDTH)); +#else + return 0; +#endif +} + +int VideoFileSource::height() +{ +#ifdef HAVE_OPENCV_HIGHGUI + return static_cast(reader_.vc.get(CV_CAP_PROP_FRAME_HEIGHT)); +#else + return 0; +#endif +} + +int VideoFileSource::count() +{ +#ifdef HAVE_OPENCV_HIGHGUI + return static_cast(reader_.vc.get(CV_CAP_PROP_FRAME_COUNT)); +#else + return 0; +#endif +} + +double VideoFileSource::fps() +{ +#ifdef HAVE_OPENCV_HIGHGUI + return reader_.vc.get(CV_CAP_PROP_FPS); +#else + return 0; +#endif +} + } // namespace videostab } // namespace cv diff --git a/modules/videostab/src/precomp.hpp b/modules/videostab/src/precomp.hpp index 2e3abcdfea..6a1fa7c46a 100644 --- a/modules/videostab/src/precomp.hpp +++ b/modules/videostab/src/precomp.hpp @@ -51,7 +51,6 @@ #include #include #include "opencv2/core/core.hpp" -#include "opencv2/highgui/highgui.hpp" #include "opencv2/imgproc/imgproc.hpp" #include "opencv2/video/video.hpp" #include "opencv2/features2d/features2d.hpp" diff --git a/samples/cpp/dbt_face_detection.cpp b/samples/cpp/dbt_face_detection.cpp index c22c8e406f..35386a78d0 100644 --- a/samples/cpp/dbt_face_detection.cpp +++ b/samples/cpp/dbt_face_detection.cpp @@ -38,7 +38,7 @@ class CascadeDetectorAdapter: public DetectionBasedTracker::IDetector cv::Ptr Detector; }; -int main(int argc, char* argv[]) +int main(int , char** ) { namedWindow(WindowName);