Merge pull request #5757 from alalek:merge-2.4

This commit is contained in:
Vadim Pisarevsky 2015-12-08 11:51:29 +00:00
commit 9c0a5523e4
15 changed files with 210 additions and 116 deletions

View File

@ -5,21 +5,26 @@ if (WIN32 AND NOT ARM)
message(FATAL_ERROR "BUILD_TBB option supports Windows on ARM only!\nUse regular official TBB build instead of the BUILD_TBB option!") message(FATAL_ERROR "BUILD_TBB option supports Windows on ARM only!\nUse regular official TBB build instead of the BUILD_TBB option!")
endif() endif()
if (WIN32 AND ARM) set(tbb_ver "tbb43_20141204oss")
# 4.1 update 4 - The first release that supports Windows RT. Hangs on some Android devices set(tbb_url "http://www.threadingbuildingblocks.org/sites/default/files/software_releases/source/tbb43_20141204oss_src.tgz")
set(tbb_ver "tbb41_20130613oss") set(tbb_md5 "e903dd92d9433701f097fa7ca29a3c1f")
set(tbb_url "http://threadingbuildingblocks.org/sites/default/files/software_releases/source/tbb41_20130613oss_src.tgz") set(tbb_version_file "version_string.ver")
set(tbb_md5 "108c8c1e481b0aaea61878289eb28b6a") ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4702)
set(tbb_version_file "version_string.ver") ocv_warnings_disable(CMAKE_CXX_FLAGS -Wshadow)
ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4702)
else() # 4.1 update 4 - The first release that supports Windows RT. Hangs on some Android devices
# 4.1 update 2 - works fine #set(tbb_ver "tbb41_20130613oss")
set(tbb_ver "tbb41_20130116oss") #set(tbb_url "http://threadingbuildingblocks.org/sites/default/files/software_releases/source/tbb41_20130613oss_src.tgz")
set(tbb_url "http://threadingbuildingblocks.org/sites/default/files/software_releases/source/tbb41_20130116oss_src.tgz") #set(tbb_md5 "108c8c1e481b0aaea61878289eb28b6a")
set(tbb_md5 "3809790e1001a1b32d59c9fee590ee85") #set(tbb_version_file "version_string.ver")
set(tbb_version_file "version_string.ver") #ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4702)
ocv_warnings_disable(CMAKE_CXX_FLAGS -Wshadow)
endif() # 4.1 update 2 - works fine
#set(tbb_ver "tbb41_20130116oss")
#set(tbb_url "http://threadingbuildingblocks.org/sites/default/files/software_releases/source/tbb41_20130116oss_src.tgz")
#set(tbb_md5 "3809790e1001a1b32d59c9fee590ee85")
#set(tbb_version_file "version_string.ver")
#ocv_warnings_disable(CMAKE_CXX_FLAGS -Wshadow)
# 4.1 update 3 dev - Hangs on some Android devices # 4.1 update 3 dev - Hangs on some Android devices
#set(tbb_ver "tbb41_20130401oss") #set(tbb_ver "tbb41_20130401oss")
@ -97,7 +102,7 @@ if(NOT EXISTS "${tbb_tarball}")
message(STATUS "Downloading ${tbb_ver}_src.tgz") message(STATUS "Downloading ${tbb_ver}_src.tgz")
file(DOWNLOAD "${tbb_url}" "${tbb_tarball}" TIMEOUT 600 STATUS __statvar) file(DOWNLOAD "${tbb_url}" "${tbb_tarball}" TIMEOUT 600 STATUS __statvar)
if(NOT __statvar EQUAL 0) if(NOT __statvar EQUAL 0)
message(FATAL_ERROR "Failed to download TBB sources: ${tbb_url}") message(FATAL_ERROR "Failed to download TBB sources (${__statvar}): ${tbb_url}")
endif() endif()
file(MD5 "${tbb_tarball}" tbb_local_md5) file(MD5 "${tbb_tarball}" tbb_local_md5)
if(NOT tbb_local_md5 STREQUAL tbb_md5) if(NOT tbb_local_md5 STREQUAL tbb_md5)
@ -153,6 +158,7 @@ if (WIN32)
set(CMAKE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} /APPCONTAINER") set(CMAKE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} /APPCONTAINER")
else() else()
add_definitions(-D__TBB_DYNAMIC_LOAD_ENABLED=0 #required add_definitions(-D__TBB_DYNAMIC_LOAD_ENABLED=0 #required
-D__TBB_WEAK_SYMBOLS_PRESENT=0 #required for 4.3
-D__TBB_BUILD=1 #required -D__TBB_BUILD=1 #required
-D__TBB_SURVIVE_THREAD_SWITCH=0 #no cilk support -D__TBB_SURVIVE_THREAD_SWITCH=0 #no cilk support
-DTBB_USE_DEBUG=0 #just to be sure -DTBB_USE_DEBUG=0 #just to be sure

View File

@ -603,6 +603,9 @@ if(HAVE_CUDA)
if(HAVE_CUFFT) if(HAVE_CUFFT)
set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} ${CUDA_cufft_LIBRARY}) set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} ${CUDA_cufft_LIBRARY})
endif() endif()
foreach(p ${CUDA_LIBS_PATH})
set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} -L${p})
endforeach()
endif() endif()
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
# Solution folders: # Solution folders:

View File

@ -206,7 +206,7 @@ bool CvCascadeClassifier::train( const string _cascadeDirName,
cout << endl << "===== TRAINING " << i << "-stage =====" << endl; cout << endl << "===== TRAINING " << i << "-stage =====" << endl;
cout << "<BEGIN" << endl; cout << "<BEGIN" << endl;
if ( !updateTrainingSet( tempLeafFARate ) ) if ( !updateTrainingSet( requiredLeafFARate, tempLeafFARate ) )
{ {
cout << "Train dataset for temp stage can not be filled. " cout << "Train dataset for temp stage can not be filled. "
"Branch training terminated." << endl; "Branch training terminated." << endl;
@ -297,17 +297,17 @@ int CvCascadeClassifier::predict( int sampleIdx )
return 1; return 1;
} }
bool CvCascadeClassifier::updateTrainingSet( double& acceptanceRatio) bool CvCascadeClassifier::updateTrainingSet( double minimumAcceptanceRatio, double& acceptanceRatio)
{ {
int64 posConsumed = 0, negConsumed = 0; int64 posConsumed = 0, negConsumed = 0;
imgReader.restart(); imgReader.restart();
int posCount = fillPassedSamples( 0, numPos, true, posConsumed ); int posCount = fillPassedSamples( 0, numPos, true, 0, posConsumed );
if( !posCount ) if( !posCount )
return false; return false;
cout << "POS count : consumed " << posCount << " : " << (int)posConsumed << endl; cout << "POS count : consumed " << posCount << " : " << (int)posConsumed << endl;
int proNumNeg = cvRound( ( ((double)numNeg) * ((double)posCount) ) / numPos ); // apply only a fraction of negative samples. double is required since overflow is possible int proNumNeg = cvRound( ( ((double)numNeg) * ((double)posCount) ) / numPos ); // apply only a fraction of negative samples. double is required since overflow is possible
int negCount = fillPassedSamples( posCount, proNumNeg, false, negConsumed ); int negCount = fillPassedSamples( posCount, proNumNeg, false, minimumAcceptanceRatio, negConsumed );
if ( !negCount ) if ( !negCount )
return false; return false;
@ -317,7 +317,7 @@ bool CvCascadeClassifier::updateTrainingSet( double& acceptanceRatio)
return true; return true;
} }
int CvCascadeClassifier::fillPassedSamples( int first, int count, bool isPositive, int64& consumed ) int CvCascadeClassifier::fillPassedSamples( int first, int count, bool isPositive, double minimumAcceptanceRatio, int64& consumed )
{ {
int getcount = 0; int getcount = 0;
Mat img(cascadeParams.winSize, CV_8UC1); Mat img(cascadeParams.winSize, CV_8UC1);
@ -325,6 +325,9 @@ int CvCascadeClassifier::fillPassedSamples( int first, int count, bool isPositiv
{ {
for( ; ; ) for( ; ; )
{ {
if( consumed != 0 && ((double)getcount+1)/(double)(int64)consumed <= minimumAcceptanceRatio )
return getcount;
bool isGetImg = isPositive ? imgReader.getPos( img ) : bool isGetImg = isPositive ? imgReader.getPos( img ) :
imgReader.getNeg( img ); imgReader.getNeg( img );
if( !isGetImg ) if( !isGetImg )

View File

@ -100,8 +100,8 @@ private:
int predict( int sampleIdx ); int predict( int sampleIdx );
void save( const std::string cascadeDirName, bool baseFormat = false ); void save( const std::string cascadeDirName, bool baseFormat = false );
bool load( const std::string cascadeDirName ); bool load( const std::string cascadeDirName );
bool updateTrainingSet( double& acceptanceRatio ); bool updateTrainingSet( double minimumAcceptanceRatio, double& acceptanceRatio );
int fillPassedSamples( int first, int count, bool isPositive, int64& consumed ); int fillPassedSamples( int first, int count, bool isPositive, double requiredAcceptanceRatio, int64& consumed );
void writeParams( cv::FileStorage &fs ) const; void writeParams( cv::FileStorage &fs ) const;
void writeStages( cv::FileStorage &fs, const cv::Mat& featureMap ) const; void writeStages( cv::FileStorage &fs, const cv::Mat& featureMap ) const;

View File

@ -12,7 +12,7 @@ endif(WITH_VFW)
# --- GStreamer --- # --- GStreamer ---
ocv_clear_vars(HAVE_GSTREAMER) ocv_clear_vars(HAVE_GSTREAMER)
# try to find gstreamer 1.x first # try to find gstreamer 1.x first if 0.10 was not requested
if(WITH_GSTREAMER AND NOT WITH_GSTREAMER_0_10) if(WITH_GSTREAMER AND NOT WITH_GSTREAMER_0_10)
CHECK_MODULE(gstreamer-base-1.0 HAVE_GSTREAMER_BASE) CHECK_MODULE(gstreamer-base-1.0 HAVE_GSTREAMER_BASE)
CHECK_MODULE(gstreamer-video-1.0 HAVE_GSTREAMER_VIDEO) CHECK_MODULE(gstreamer-video-1.0 HAVE_GSTREAMER_VIDEO)
@ -29,7 +29,7 @@ if(WITH_GSTREAMER AND NOT WITH_GSTREAMER_0_10)
set(GSTREAMER_PBUTILS_VERSION ${ALIASOF_gstreamer-pbutils-1.0_VERSION}) set(GSTREAMER_PBUTILS_VERSION ${ALIASOF_gstreamer-pbutils-1.0_VERSION})
endif() endif()
endif(WITH_GSTREAMER AND NOT WITH_GSTREAMER_0_10) endif()
# if gstreamer 1.x was not found, or we specified we wanted 0.10, try to find it # if gstreamer 1.x was not found, or we specified we wanted 0.10, try to find it
if(WITH_GSTREAMER AND NOT HAVE_GSTREAMER OR WITH_GSTREAMER_0_10) if(WITH_GSTREAMER AND NOT HAVE_GSTREAMER OR WITH_GSTREAMER_0_10)

View File

@ -503,17 +503,15 @@ endmacro()
# convert list of paths to libraries names without lib prefix # convert list of paths to libraries names without lib prefix
macro(ocv_convert_to_lib_name var) function(ocv_convert_to_lib_name var)
set(__tmp "") set(tmp "")
foreach(path ${ARGN}) foreach(path ${ARGN})
get_filename_component(__tmp_name "${path}" NAME_WE) get_filename_component(tmp_name "${path}" NAME_WE)
string(REGEX REPLACE "^lib" "" __tmp_name ${__tmp_name}) string(REGEX REPLACE "^lib" "" tmp_name "${tmp_name}")
list(APPEND __tmp "${__tmp_name}") list(APPEND tmp "${tmp_name}")
endforeach() endforeach()
set(${var} ${__tmp}) set(${var} ${tmp} PARENT_SCOPE)
unset(__tmp) endfunction()
unset(__tmp_name)
endmacro()
# add install command # add install command

View File

@ -12,6 +12,7 @@
// //
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., all rights reserved. // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
// Copyright (C) 2015, Itseez Inc., all rights reserved.
// Third party copyrights are property of their respective owners. // Third party copyrights are property of their respective owners.
// //
// Redistribution and use in source and binary forms, with or without modification, // Redistribution and use in source and binary forms, with or without modification,
@ -564,6 +565,9 @@ void CV_HomographyTest::run(int)
default: continue; default: continue;
} }
} }
delete[]src_data;
src_data = NULL;
} }
} }

View File

@ -311,6 +311,10 @@ void SimpleBlobDetectorImpl::detect(InputArray image, std::vector<cv::KeyPoint>&
else else
grayscaleImage = image.getMat(); grayscaleImage = image.getMat();
if (grayscaleImage.type() != CV_8UC1) {
CV_Error(Error::StsUnsupportedFormat, "Blob detector only supports 8-bit images!");
}
std::vector < std::vector<Center> > centers; std::vector < std::vector<Center> > centers;
for (double thresh = params.minThreshold; thresh < params.maxThreshold; thresh += params.thresholdStep) for (double thresh = params.minThreshold; thresh < params.maxThreshold; thresh += params.thresholdStep)
{ {

View File

@ -220,7 +220,11 @@ void GpuMatcher::match(const ImageFeatures &features1, const ImageFeatures &feat
descriptors1_.upload(features1.descriptors); descriptors1_.upload(features1.descriptors);
descriptors2_.upload(features2.descriptors); descriptors2_.upload(features2.descriptors);
Ptr<cuda::DescriptorMatcher> matcher = cuda::DescriptorMatcher::createBFMatcher(NORM_L2); //TODO: NORM_L1 allows to avoid matcher crashes for ORB features, but is not absolutely correct for them.
// The best choice for ORB features is NORM_HAMMING, but it is incorrect for SURF features.
// More accurate fix in this place should be done in the future -- the type of the norm
// should be either a parameter of this method, or a field of the class.
Ptr<cuda::DescriptorMatcher> matcher = cuda::DescriptorMatcher::createBFMatcher(NORM_L1);
MatchesSet matches; MatchesSet matches;

View File

@ -166,10 +166,12 @@ CV_IMPL CvCapture * cvCreateCameraCapture (int index)
#ifdef HAVE_GSTREAMER #ifdef HAVE_GSTREAMER
if (!capture) if (!capture)
capture = cvCreateCapture_GStreamer(CV_CAP_GSTREAMER_V4L2, 0); capture = cvCreateCapture_GStreamer(CV_CAP_GSTREAMER_V4L2,
reinterpret_cast<char *>(index));
if (!capture) if (!capture)
capture = cvCreateCapture_GStreamer(CV_CAP_GSTREAMER_V4L, 0); capture = cvCreateCapture_GStreamer(CV_CAP_GSTREAMER_V4L,
reinterpret_cast<char *>(index));
#endif #endif
if (pref) break; // CV_CAP_VFW if (pref) break; // CV_CAP_VFW

View File

@ -75,10 +75,13 @@
#if GST_VERSION_MAJOR == 0 #if GST_VERSION_MAJOR == 0
#define COLOR_ELEM "ffmpegcolorspace" #define COLOR_ELEM "ffmpegcolorspace"
#define COLOR_ELEM_NAME "ffmpegcsp"
#elif FULL_GST_VERSION < VERSION_NUM(1,5,0) #elif FULL_GST_VERSION < VERSION_NUM(1,5,0)
#define COLOR_ELEM "videoconvert" #define COLOR_ELEM "videoconvert"
#define COLOR_ELEM_NAME COLOR_ELEM
#else #else
#define COLOR_ELEM "autovideoconvert" #define COLOR_ELEM "autovideoconvert"
#define COLOR_ELEM_NAME COLOR_ELEM
#endif #endif
void toFraction(double decimal, double &numerator, double &denominator); void toFraction(double decimal, double &numerator, double &denominator);
@ -142,6 +145,7 @@ protected:
gpointer data); gpointer data);
GstElement* pipeline; GstElement* pipeline;
GstElement* uridecodebin; GstElement* uridecodebin;
GstElement* v4l2src;
GstElement* color; GstElement* color;
GstElement* sink; GstElement* sink;
#if GST_VERSION_MAJOR > 0 #if GST_VERSION_MAJOR > 0
@ -164,6 +168,7 @@ void CvCapture_GStreamer::init()
{ {
pipeline = NULL; pipeline = NULL;
uridecodebin = NULL; uridecodebin = NULL;
v4l2src = NULL;
color = NULL; color = NULL;
sink = NULL; sink = NULL;
#if GST_VERSION_MAJOR > 0 #if GST_VERSION_MAJOR > 0
@ -368,9 +373,7 @@ void CvCapture_GStreamer::startPipeline()
if (status == GST_STATE_CHANGE_ASYNC) if (status == GST_STATE_CHANGE_ASYNC)
{ {
// wait for status update // wait for status update
GstState st1; status = gst_element_get_state(pipeline, NULL, NULL, GST_CLOCK_TIME_NONE);
GstState st2;
status = gst_element_get_state(pipeline, &st1, &st2, GST_CLOCK_TIME_NONE);
} }
if (status == GST_STATE_CHANGE_FAILURE) if (status == GST_STATE_CHANGE_FAILURE)
{ {
@ -619,7 +622,9 @@ bool CvCapture_GStreamer::open( int type, const char* filename )
stream = true; stream = true;
manualpipeline = true; manualpipeline = true;
} }
} else { }
else
{
stream = true; stream = true;
uri = g_strdup(filename); uri = g_strdup(filename);
} }
@ -640,68 +645,86 @@ bool CvCapture_GStreamer::open( int type, const char* filename )
uridecodebin = gst_element_make_from_uri(GST_URI_SRC, uri, "src", NULL); uridecodebin = gst_element_make_from_uri(GST_URI_SRC, uri, "src", NULL);
#endif #endif
element_from_uri = true; element_from_uri = true;
}else{ }
else
{
uridecodebin = gst_element_factory_make("uridecodebin", NULL); uridecodebin = gst_element_factory_make("uridecodebin", NULL);
g_object_set(G_OBJECT(uridecodebin), "uri", uri, NULL); g_object_set(G_OBJECT(uridecodebin), "uri", uri, NULL);
} }
g_free(protocol); g_free(protocol);
if(!uridecodebin) { if(!uridecodebin)
{
//fprintf(stderr, "GStreamer: Error opening bin: %s\n", err->message); //fprintf(stderr, "GStreamer: Error opening bin: %s\n", err->message);
close(); close();
return false; return false;
} }
} }
if(manualpipeline) if (manualpipeline)
{ {
GstIterator *it = NULL; GstIterator *it = gst_bin_iterate_elements(GST_BIN(uridecodebin));
#if GST_VERSION_MAJOR == 0
it = gst_bin_iterate_sinks(GST_BIN(uridecodebin));
if(gst_iterator_next(it, (gpointer *)&sink) != GST_ITERATOR_OK) {
CV_ERROR(CV_StsError, "GStreamer: cannot find appsink in manual pipeline\n");
return false;
}
#else
it = gst_bin_iterate_sinks (GST_BIN(uridecodebin));
gboolean done = FALSE;
GstElement *element = NULL; GstElement *element = NULL;
gboolean done = false;
gchar* name = NULL; gchar* name = NULL;
#if GST_VERSION_MAJOR > 0
GValue value = G_VALUE_INIT; GValue value = G_VALUE_INIT;
#endif
while (!done) { while (!done)
switch (gst_iterator_next (it, &value)) { {
#if GST_VERSION_MAJOR > 0
switch (gst_iterator_next (it, &value))
{
case GST_ITERATOR_OK: case GST_ITERATOR_OK:
element = GST_ELEMENT (g_value_get_object (&value)); element = GST_ELEMENT (g_value_get_object (&value));
name = gst_element_get_name(element); #else
if (name){ switch (gst_iterator_next (it, (gpointer *)&element))
if(strstr(name, "opencvsink") != NULL || strstr(name, "appsink") != NULL) { {
sink = GST_ELEMENT ( gst_object_ref (element) ); case GST_ITERATOR_OK:
done = TRUE; #endif
} name = gst_element_get_name(element);
g_free(name); if (name)
} {
g_value_unset (&value); if (strstr(name, "opencvsink") != NULL || strstr(name, "appsink") != NULL)
{
sink = GST_ELEMENT ( gst_object_ref (element) );
}
else if (strstr(name, COLOR_ELEM_NAME) != NULL)
{
color = GST_ELEMENT ( gst_object_ref (element) );
}
else if (strstr(name, "v4l") != NULL)
{
v4l2src = GST_ELEMENT ( gst_object_ref (element) );
}
g_free(name);
break; done = sink && color && v4l2src;
}
#if GST_VERSION_MAJOR > 0
g_value_unset (&value);
#endif
break;
case GST_ITERATOR_RESYNC: case GST_ITERATOR_RESYNC:
gst_iterator_resync (it); gst_iterator_resync (it);
break; break;
case GST_ITERATOR_ERROR: case GST_ITERATOR_ERROR:
case GST_ITERATOR_DONE: case GST_ITERATOR_DONE:
done = TRUE; done = TRUE;
break; break;
} }
} }
gst_iterator_free (it); gst_iterator_free (it);
if (!sink)
if (!sink){ {
CV_ERROR(CV_StsError, "GStreamer: cannot find appsink in manual pipeline\n"); CV_ERROR(CV_StsError, "GStreamer: cannot find appsink in manual pipeline\n");
return false; return false;
} }
#endif
pipeline = uridecodebin; pipeline = uridecodebin;
} }
else else
@ -714,18 +737,23 @@ bool CvCapture_GStreamer::open( int type, const char* filename )
gst_bin_add_many(GST_BIN(pipeline), uridecodebin, color, sink, NULL); gst_bin_add_many(GST_BIN(pipeline), uridecodebin, color, sink, NULL);
if(element_from_uri) { if(element_from_uri)
if(!gst_element_link(uridecodebin, color)) { {
if(!gst_element_link(uridecodebin, color))
{
CV_ERROR(CV_StsError, "GStreamer: cannot link color -> sink\n"); CV_ERROR(CV_StsError, "GStreamer: cannot link color -> sink\n");
gst_object_unref(pipeline); gst_object_unref(pipeline);
pipeline = NULL; pipeline = NULL;
return false; return false;
} }
}else{ }
else
{
g_signal_connect(uridecodebin, "pad-added", G_CALLBACK(newPad), color); g_signal_connect(uridecodebin, "pad-added", G_CALLBACK(newPad), color);
} }
if(!gst_element_link(color, sink)) { if(!gst_element_link(color, sink))
{
CV_ERROR(CV_StsError, "GStreamer: cannot link color -> sink\n"); CV_ERROR(CV_StsError, "GStreamer: cannot link color -> sink\n");
gst_object_unref(pipeline); gst_object_unref(pipeline);
pipeline = NULL; pipeline = NULL;
@ -753,16 +781,13 @@ bool CvCapture_GStreamer::open( int type, const char* filename )
gst_app_sink_set_caps(GST_APP_SINK(sink), caps); gst_app_sink_set_caps(GST_APP_SINK(sink), caps);
gst_caps_unref(caps); gst_caps_unref(caps);
// For video files only: set pipeline to PAUSED state to get its duration
if (file)
{ {
status = gst_element_set_state(GST_ELEMENT(pipeline), GST_STATE_PAUSED); status = gst_element_set_state(GST_ELEMENT(pipeline),
file ? GST_STATE_PAUSED : GST_STATE_PLAYING);
if (status == GST_STATE_CHANGE_ASYNC) if (status == GST_STATE_CHANGE_ASYNC)
{ {
// wait for status update // wait for status update
GstState st1; status = gst_element_get_state(pipeline, NULL, NULL, GST_CLOCK_TIME_NONE);
GstState st2;
status = gst_element_get_state(pipeline, &st1, &st2, GST_CLOCK_TIME_NONE);
} }
if (status == GST_STATE_CHANGE_FAILURE) if (status == GST_STATE_CHANGE_FAILURE)
{ {
@ -813,14 +838,9 @@ bool CvCapture_GStreamer::open( int type, const char* filename )
fps = (double)num/(double)denom; fps = (double)num/(double)denom;
// GST_DEBUG_BIN_TO_DOT_FILE(GST_BIN(pipeline), GST_DEBUG_GRAPH_SHOW_ALL, "pipeline"); // GST_DEBUG_BIN_TO_DOT_FILE(GST_BIN(pipeline), GST_DEBUG_GRAPH_SHOW_ALL, "pipeline")
}
else stopPipeline();
{
duration = -1;
width = -1;
height = -1;
fps = -1;
} }
__END__; __END__;
@ -851,7 +871,7 @@ double CvCapture_GStreamer::getProperty( int propId ) const
if(!pipeline) { if(!pipeline) {
CV_WARN("GStreamer: no pipeline"); CV_WARN("GStreamer: no pipeline");
return false; return 0;
} }
switch(propId) { switch(propId) {
@ -860,7 +880,7 @@ double CvCapture_GStreamer::getProperty( int propId ) const
status = gst_element_query_position(sink, FORMAT, &value); status = gst_element_query_position(sink, FORMAT, &value);
if(!status) { if(!status) {
CV_WARN("GStreamer: unable to query position of stream"); CV_WARN("GStreamer: unable to query position of stream");
return false; return 0;
} }
return value * 1e-6; // nano seconds to milli seconds return value * 1e-6; // nano seconds to milli seconds
case CV_CAP_PROP_POS_FRAMES: case CV_CAP_PROP_POS_FRAMES:
@ -868,7 +888,7 @@ double CvCapture_GStreamer::getProperty( int propId ) const
status = gst_element_query_position(sink, FORMAT, &value); status = gst_element_query_position(sink, FORMAT, &value);
if(!status) { if(!status) {
CV_WARN("GStreamer: unable to query position of stream"); CV_WARN("GStreamer: unable to query position of stream");
return false; return 0;
} }
return value; return value;
case CV_CAP_PROP_POS_AVI_RATIO: case CV_CAP_PROP_POS_AVI_RATIO:
@ -876,7 +896,7 @@ double CvCapture_GStreamer::getProperty( int propId ) const
status = gst_element_query_position(sink, FORMAT, &value); status = gst_element_query_position(sink, FORMAT, &value);
if(!status) { if(!status) {
CV_WARN("GStreamer: unable to query position of stream"); CV_WARN("GStreamer: unable to query position of stream");
return false; return 0;
} }
return ((double) value) / GST_FORMAT_PERCENT_MAX; return ((double) value) / GST_FORMAT_PERCENT_MAX;
case CV_CAP_PROP_FRAME_WIDTH: case CV_CAP_PROP_FRAME_WIDTH:
@ -895,6 +915,21 @@ double CvCapture_GStreamer::getProperty( int propId ) const
case CV_CAP_PROP_CONTRAST: case CV_CAP_PROP_CONTRAST:
case CV_CAP_PROP_SATURATION: case CV_CAP_PROP_SATURATION:
case CV_CAP_PROP_HUE: case CV_CAP_PROP_HUE:
if (v4l2src)
{
const gchar * propName =
propId == CV_CAP_PROP_BRIGHTNESS ? "brightness" :
propId == CV_CAP_PROP_CONTRAST ? "contrast" :
propId == CV_CAP_PROP_SATURATION ? "saturation" :
propId == CV_CAP_PROP_HUE ? "hue" : NULL;
if (propName)
{
gint32 value32 = 0;
g_object_get(G_OBJECT(v4l2src), propName, &value32, NULL);
return value32;
}
}
case CV_CAP_PROP_GAIN: case CV_CAP_PROP_GAIN:
case CV_CAP_PROP_CONVERT_RGB: case CV_CAP_PROP_CONVERT_RGB:
break; break;
@ -911,7 +946,7 @@ double CvCapture_GStreamer::getProperty( int propId ) const
#undef FORMAT #undef FORMAT
return false; return 0;
} }
/*! /*!
@ -990,6 +1025,21 @@ bool CvCapture_GStreamer::setProperty( int propId, double value )
case CV_CAP_PROP_CONTRAST: case CV_CAP_PROP_CONTRAST:
case CV_CAP_PROP_SATURATION: case CV_CAP_PROP_SATURATION:
case CV_CAP_PROP_HUE: case CV_CAP_PROP_HUE:
if (v4l2src)
{
const gchar * propName =
propId == CV_CAP_PROP_BRIGHTNESS ? "brightness" :
propId == CV_CAP_PROP_CONTRAST ? "contrast" :
propId == CV_CAP_PROP_SATURATION ? "saturation" :
propId == CV_CAP_PROP_HUE ? "hue" : NULL;
if (propName)
{
gint32 value32 = cv::saturate_cast<gint32>(value);
g_object_set(G_OBJECT(v4l2src), propName, &value32, NULL);
return true;
}
}
case CV_CAP_PROP_GAIN: case CV_CAP_PROP_GAIN:
case CV_CAP_PROP_CONVERT_RGB: case CV_CAP_PROP_CONVERT_RGB:
break; break;

View File

@ -67,10 +67,11 @@ class CvCapture_Images : public CvCapture
public: public:
CvCapture_Images() CvCapture_Images()
{ {
filename = 0; filename = NULL;
currentframe = firstframe = 0; currentframe = firstframe = 0;
length = 0; length = 0;
frame = 0; frame = NULL;
grabbedInOpen = false;
} }
virtual ~CvCapture_Images() virtual ~CvCapture_Images()
@ -92,6 +93,7 @@ protected:
unsigned length; // length of sequence unsigned length; // length of sequence
IplImage* frame; IplImage* frame;
bool grabbedInOpen;
}; };
@ -100,7 +102,7 @@ void CvCapture_Images::close()
if( filename ) if( filename )
{ {
free(filename); free(filename);
filename = 0; filename = NULL;
} }
currentframe = firstframe = 0; currentframe = firstframe = 0;
length = 0; length = 0;
@ -113,17 +115,25 @@ bool CvCapture_Images::grabFrame()
char str[_MAX_PATH]; char str[_MAX_PATH];
sprintf(str, filename, firstframe + currentframe); sprintf(str, filename, firstframe + currentframe);
if (grabbedInOpen)
{
grabbedInOpen = false;
++currentframe;
return frame != NULL;
}
cvReleaseImage(&frame); cvReleaseImage(&frame);
frame = cvLoadImage(str, CV_LOAD_IMAGE_ANYDEPTH | CV_LOAD_IMAGE_ANYCOLOR); frame = cvLoadImage(str, CV_LOAD_IMAGE_ANYDEPTH | CV_LOAD_IMAGE_ANYCOLOR);
if( frame ) if( frame )
currentframe++; currentframe++;
return frame != 0; return frame != NULL;
} }
IplImage* CvCapture_Images::retrieveFrame(int) IplImage* CvCapture_Images::retrieveFrame(int)
{ {
return frame; return grabbedInOpen ? NULL : frame;
} }
double CvCapture_Images::getProperty(int id) const double CvCapture_Images::getProperty(int id) const
@ -168,6 +178,8 @@ bool CvCapture_Images::setProperty(int id, double value)
value = length - 1; value = length - 1;
} }
currentframe = cvRound(value); currentframe = cvRound(value);
if (currentframe != 0)
grabbedInOpen = false; // grabbed frame is not valid anymore
return true; return true;
case CV_CAP_PROP_POS_AVI_RATIO: case CV_CAP_PROP_POS_AVI_RATIO:
if(value > 1) { if(value > 1) {
@ -178,6 +190,8 @@ bool CvCapture_Images::setProperty(int id, double value)
value = 0; value = 0;
} }
currentframe = cvRound((length - 1) * value); currentframe = cvRound((length - 1) * value);
if (currentframe != 0)
grabbedInOpen = false; // grabbed frame is not valid anymore
return true; return true;
} }
CV_WARN("unknown/unhandled property\n"); CV_WARN("unknown/unhandled property\n");
@ -280,7 +294,13 @@ bool CvCapture_Images::open(const char * _filename)
} }
firstframe = offset; firstframe = offset;
return true;
// grab frame to enable properties retrieval
bool grabRes = grabFrame();
grabbedInOpen = true;
currentframe = 0;
return grabRes;
} }
@ -292,7 +312,7 @@ CvCapture* cvCreateFileCapture_Images(const char * filename)
return capture; return capture;
delete capture; delete capture;
return 0; return NULL;
} }
// //

View File

@ -431,6 +431,10 @@ TEST(Videoio_Video_parallel_writers_and_readers, accuracy)
if (code == 1) if (code == 1)
std::cerr << "Couldn't delete " << *i << std::endl; std::cerr << "Couldn't delete " << *i << std::endl;
} }
// delete the readers
for (std::vector<VideoCapture *>::iterator i = readers.begin(), end = readers.end(); i != end; ++i)
delete *i;
} }
#endif #endif

View File

@ -81,6 +81,10 @@ if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND)
file(GLOB all_samples RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) file(GLOB all_samples RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp)
if(NOT WITH_OPENGL)
list(REMOVE_ITEM all_samples "opengl.cpp")
endif(NOT WITH_OPENGL)
foreach(sample_filename ${all_samples}) foreach(sample_filename ${all_samples})
get_filename_component(sample ${sample_filename} NAME_WE) get_filename_component(sample ${sample_filename} NAME_WE)
file(GLOB sample_srcs RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${sample}.*) file(GLOB sample_srcs RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${sample}.*)
@ -92,6 +96,9 @@ endif()
if(INSTALL_C_EXAMPLES AND NOT WIN32) if(INSTALL_C_EXAMPLES AND NOT WIN32)
file(GLOB install_list *.c *.cpp *.jpg *.png *.data makefile.* build_all.sh *.dsp *.cmd ) file(GLOB install_list *.c *.cpp *.jpg *.png *.data makefile.* build_all.sh *.dsp *.cmd )
if(NOT WITH_OPENGL)
list(REMOVE_ITEM all_samples "opengl.cpp")
endif(NOT WITH_OPENGL)
install(FILES ${install_list} install(FILES ${install_list}
DESTINATION ${OPENCV_SAMPLES_SRC_INSTALL_PATH}/gpu DESTINATION ${OPENCV_SAMPLES_SRC_INSTALL_PATH}/gpu
PERMISSIONS OWNER_READ GROUP_READ WORLD_READ COMPONENT samples) PERMISSIONS OWNER_READ GROUP_READ WORLD_READ COMPONENT samples)

View File

@ -1,13 +1,4 @@
#include <iostream> #include <iostream>
#include "cvconfig.h"
#ifndef HAVE_OPENGL
int main()
{
std::cerr << "Library was built without OpenGL support" << std::endl;
return -1;
}
#else
#ifdef WIN32 #ifdef WIN32
#define WIN32_LEAN_AND_MEAN 1 #define WIN32_LEAN_AND_MEAN 1
@ -124,5 +115,3 @@ int main(int argc, char* argv[])
return 0; return 0;
} }
#endif