1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-31 08:13:04 +04:00

Merge branch 4.x

This commit is contained in:
Alexander Smorkalov
2026-04-29 15:37:29 +03:00
73 changed files with 1719 additions and 1113 deletions
+12 -3
View File
@@ -526,15 +526,14 @@ inline static std::string _opencv_ffmpeg_get_error_string(int error_code)
static inline int64_t to_avtb(int64_t ts, AVRational tb)
{
return av_rescale_q(ts, tb, AV_TIME_BASE_Q);
return av_rescale_q(ts, tb, av_make_q(1, AV_TIME_BASE));
}
static inline int64_t from_avtb(int64_t ts_avtb, AVRational tb)
{
return av_rescale_q(ts_avtb, AV_TIME_BASE_Q, tb);
return av_rescale_q(ts_avtb, av_make_q(1, AV_TIME_BASE), tb);
}
struct CvCapture_FFMPEG
{
bool open(const char* filename, int index, const Ptr<IStreamReader>& stream, const VideoCaptureParameters& params);
@@ -624,6 +623,7 @@ struct CvCapture_FFMPEG
int use_opencl;
int extraDataIdx;
int requestedThreads;
int image_seq_start; // image2 demuxer start_number; -1 means unset
};
void CvCapture_FFMPEG::init()
@@ -679,6 +679,7 @@ void CvCapture_FFMPEG::init()
use_opencl = 0;
extraDataIdx = 1;
requestedThreads = cv::getNumberOfCPUs();
image_seq_start = -1;
}
@@ -1160,6 +1161,10 @@ bool CvCapture_FFMPEG::open(const char* _filename, int index, const Ptr<IStreamR
{
nThreads = requestedThreads = params.get<int>(CAP_PROP_N_THREADS);
}
if (params.has(CAP_PROP_IMAGE_SEQ_START))
{
image_seq_start = params.get<int>(CAP_PROP_IMAGE_SEQ_START);
}
if (params.warnUnusedParameters())
{
CV_LOG_ERROR(NULL, "VIDEOIO/FFMPEG: unsupported parameters in .open(), see logger INFO channel for details. Bailout");
@@ -1194,6 +1199,10 @@ bool CvCapture_FFMPEG::open(const char* _filename, int index, const Ptr<IStreamR
av_dict_set(&dict, "rtsp_transport", "tcp", 0);
#endif
}
if (image_seq_start >= 0)
{
av_dict_set_int(&dict, "start_number", image_seq_start, 0);
}
CV_FFMPEG_FMT_CONST AVInputFormat* input_format = NULL;
AVDictionaryEntry* entry = av_dict_get(dict, "input_format", NULL, 0);
if (entry != 0)
+21 -10
View File
@@ -77,11 +77,6 @@ public:
{
init();
}
CvCapture_Images(const String& _filename)
{
init();
open(_filename);
}
virtual ~CvCapture_Images() CV_OVERRIDE
{
@@ -94,7 +89,7 @@ public:
virtual bool isOpened() const CV_OVERRIDE;
virtual int getCaptureDomain() /*const*/ CV_OVERRIDE { return cv::CAP_IMAGES; }
bool open(const String&);
bool open(const String&, int image_seq_start = -1);
void close();
protected:
std::string filename_pattern; // actually a printf-pattern
@@ -285,13 +280,16 @@ std::string icvExtractPattern(const std::string& filename, unsigned *offset)
}
bool CvCapture_Images::open(const std::string& _filename)
bool CvCapture_Images::open(const std::string& _filename, int image_seq_start)
{
unsigned offset = 0;
close();
CV_Assert(!_filename.empty());
filename_pattern = icvExtractPattern(_filename, &offset);
const bool explicit_start = (image_seq_start >= 0);
if (explicit_start)
offset = static_cast<unsigned>(image_seq_start);
if (filename_pattern.empty())
{
filename_pattern = _filename;
@@ -317,7 +315,7 @@ bool CvCapture_Images::open(const std::string& _filename)
cv::String filename = cv::format(filename_pattern.c_str(), (int)(offset + length));
if (!utils::fs::exists(filename))
{
if (length == 0 && offset == 0) // allow starting with 0 or 1
if (length == 0 && offset == 0 && !explicit_start) // allow starting with 0 or 1
{
offset++;
continue;
@@ -355,9 +353,22 @@ bool CvCapture_Images::isOpened() const
return !filename_pattern.empty();
}
Ptr<IVideoCapture> create_Images_capture(const std::string &filename)
Ptr<IVideoCapture> create_Images_capture(const std::string& filename, const VideoCaptureParameters& params)
{
return makePtr<CvCapture_Images>(filename);
int image_seq_start = -1;
if (params.has(CAP_PROP_IMAGE_SEQ_START))
{
image_seq_start = params.get<int>(CAP_PROP_IMAGE_SEQ_START);
}
if (params.warnUnusedParameters())
{
CV_LOG_ERROR(NULL, "VIDEOIO/IMAGES: unsupported parameters in .open(), see logger INFO channel for details. Bailout");
return Ptr<IVideoCapture>();
}
Ptr<CvCapture_Images> cap = makePtr<CvCapture_Images>();
if (!cap->open(filename, image_seq_start))
return Ptr<IVideoCapture>();
return cap;
}
//
+1 -1
View File
@@ -343,7 +343,7 @@ Ptr<IVideoCapture> create_V4L_capture_file(const std::string &filename);
Ptr<IVideoCapture> create_OpenNI2_capture_cam( int index );
Ptr<IVideoCapture> create_OpenNI2_capture_file( const std::string &filename );
Ptr<IVideoCapture> create_Images_capture(const std::string &filename);
Ptr<IVideoCapture> create_Images_capture(const std::string& filename, const VideoCaptureParameters& params);
Ptr<IVideoWriter> create_Images_writer(const std::string& filename, int fourcc,
double fps, const Size& frameSize,
const VideoWriterParameters& params);