Commit f1fdfa1a authored by Alexander Alekhin's avatar Alexander Alekhin

Merge pull request #12623 from sturkmen72:videoio-4

parents 0f3fe957 59bf2a34
...@@ -617,14 +617,7 @@ public: ...@@ -617,14 +617,7 @@ public:
CV_WRAP VideoCapture(); CV_WRAP VideoCapture();
/** @overload /** @overload
@brief Open video file or a capturing device or a IP video stream for video capturing @brief Opens a video file or a capturing device or an IP video stream for video capturing with API Preference
Same as VideoCapture(const String& filename, int apiPreference) but using default Capture API backends
*/
CV_WRAP VideoCapture(const String& filename);
/** @overload
@brief Open video file or a capturing device or a IP video stream for video capturing with API Preference
@param filename it can be: @param filename it can be:
- name of video file (eg. `video.avi`) - name of video file (eg. `video.avi`)
...@@ -636,18 +629,19 @@ public: ...@@ -636,18 +629,19 @@ public:
implementation if multiple are available: e.g. cv::CAP_FFMPEG or cv::CAP_IMAGES or cv::CAP_DSHOW. implementation if multiple are available: e.g. cv::CAP_FFMPEG or cv::CAP_IMAGES or cv::CAP_DSHOW.
@sa The list of supported API backends cv::VideoCaptureAPIs @sa The list of supported API backends cv::VideoCaptureAPIs
*/ */
CV_WRAP VideoCapture(const String& filename, int apiPreference); CV_WRAP VideoCapture(const String& filename, int apiPreference = CAP_ANY);
/** @overload /** @overload
@brief Open a camera for video capturing @brief Opens a camera for video capturing
@param index camera_id + domain_offset (CAP_*) id of the video capturing device to open. To open default camera using default backend just pass 0. @param index id of the video capturing device to open. To open default camera using default backend just pass 0.
Use a `domain_offset` to enforce a specific reader implementation if multiple are available like cv::CAP_FFMPEG or cv::CAP_IMAGES or cv::CAP_DSHOW. (to backward compatibility usage of camera_id + domain_offset (CAP_*) is valid when apiPreference is CAP_ANY)
e.g. to open Camera 1 using the MS Media Foundation API use `index = 1 + cv::CAP_MSMF` @param apiPreference preferred Capture API backends to use. Can be used to enforce a specific reader
implementation if multiple are available: e.g. cv::CAP_DSHOW or cv::CAP_MSMF or cv::CAP_V4L.
@sa The list of supported API backends cv::VideoCaptureAPIs @sa The list of supported API backends cv::VideoCaptureAPIs
*/ */
CV_WRAP VideoCapture(int index); CV_WRAP VideoCapture(int index, int apiPreference = CAP_ANY);
/** @brief Default destructor /** @brief Default destructor
...@@ -655,37 +649,27 @@ public: ...@@ -655,37 +649,27 @@ public:
*/ */
virtual ~VideoCapture(); virtual ~VideoCapture();
/** @brief Open video file or a capturing device or a IP video stream for video capturing /** @brief Opens a video file or a capturing device or an IP video stream for video capturing.
@overload @overload
Parameters are same as the constructor VideoCapture(const String& filename) Parameters are same as the constructor VideoCapture(const String& filename, int apiPreference = CAP_ANY)
@return `true` if the file has been successfully opened @return `true` if the file has been successfully opened
The method first calls VideoCapture::release to close the already opened file or camera. The method first calls VideoCapture::release to close the already opened file or camera.
*/ */
CV_WRAP virtual bool open(const String& filename); CV_WRAP virtual bool open(const String& filename, int apiPreference = CAP_ANY);
/** @brief Open a camera for video capturing /** @brief Opens a camera for video capturing
@overload @overload
Parameters are same as the constructor VideoCapture(int index) Parameters are same as the constructor VideoCapture(int index, int apiPreference = CAP_ANY)
@return `true` if the camera has been successfully opened. @return `true` if the camera has been successfully opened.
The method first calls VideoCapture::release to close the already opened file or camera. The method first calls VideoCapture::release to close the already opened file or camera.
*/ */
CV_WRAP virtual bool open(int index); CV_WRAP virtual bool open(int index, int apiPreference = CAP_ANY);
/** @brief Open a camera for video capturing
@overload
Parameters are similar as the constructor VideoCapture(int index),except it takes an additional argument apiPreference.
Definitely, is same as open(int index) where `index=cameraNum + apiPreference`
@return `true` if the camera has been successfully opened.
*/
CV_WRAP bool open(int cameraNum, int apiPreference);
/** @brief Returns true if video capturing has been initialized already. /** @brief Returns true if video capturing has been initialized already.
...@@ -798,17 +782,6 @@ public: ...@@ -798,17 +782,6 @@ public:
*/ */
CV_WRAP virtual double get(int propId) const; CV_WRAP virtual double get(int propId) const;
/** @brief Open video file or a capturing device or a IP video stream for video capturing with API Preference
@overload
Parameters are same as the constructor VideoCapture(const String& filename, int apiPreference)
@return `true` if the file has been successfully opened
The method first calls VideoCapture::release to close the already opened file or camera.
*/
CV_WRAP virtual bool open(const String& filename, int apiPreference);
/** @brief Returns used backend API name /** @brief Returns used backend API name
@note Stream should be opened. @note Stream should be opened.
...@@ -915,6 +888,11 @@ public: ...@@ -915,6 +888,11 @@ public:
*/ */
virtual VideoWriter& operator << (const Mat& image); virtual VideoWriter& operator << (const Mat& image);
/** @overload
@sa write
*/
virtual VideoWriter& operator << (const UMat& image);
/** @brief Writes the next video frame /** @brief Writes the next video frame
@param image The written frame. In general, color images are expected in BGR format. @param image The written frame. In general, color images are expected in BGR format.
...@@ -922,7 +900,7 @@ public: ...@@ -922,7 +900,7 @@ public:
The function/method writes the specified image to video file. It must have the same size as has The function/method writes the specified image to video file. It must have the same size as has
been specified when opening the video writer. been specified when opening the video writer.
*/ */
CV_WRAP virtual void write(const Mat& image); CV_WRAP virtual void write(InputArray image);
/** @brief Sets a property in the VideoWriter. /** @brief Sets a property in the VideoWriter.
......
...@@ -59,16 +59,10 @@ VideoCapture::VideoCapture(const String& filename, int apiPreference) ...@@ -59,16 +59,10 @@ VideoCapture::VideoCapture(const String& filename, int apiPreference)
open(filename, apiPreference); open(filename, apiPreference);
} }
VideoCapture::VideoCapture(const String& filename) VideoCapture::VideoCapture(int index, int apiPreference)
{ {
CV_TRACE_FUNCTION(); CV_TRACE_FUNCTION();
open(filename, CAP_ANY); open(index, apiPreference);
}
VideoCapture::VideoCapture(int index)
{
CV_TRACE_FUNCTION();
open(index);
} }
VideoCapture::~VideoCapture() VideoCapture::~VideoCapture()
...@@ -110,19 +104,23 @@ bool VideoCapture::open(const String& filename, int apiPreference) ...@@ -110,19 +104,23 @@ bool VideoCapture::open(const String& filename, int apiPreference)
return false; return false;
} }
bool VideoCapture::open(const String& filename)
{
CV_TRACE_FUNCTION();
return open(filename, CAP_ANY);
}
bool VideoCapture::open(int cameraNum, int apiPreference) bool VideoCapture::open(int cameraNum, int apiPreference)
{ {
CV_TRACE_FUNCTION(); CV_TRACE_FUNCTION();
if (isOpened()) release(); if (isOpened()) release();
if(apiPreference==CAP_ANY)
{
// interpret preferred interface (0 = autodetect)
int backendID = (cameraNum / 100) * 100;
if (backendID)
{
cameraNum %= 100;
apiPreference = backendID;
}
}
const std::vector<VideoBackendInfo> backends = cv::videoio_registry::getAvailableBackends_CaptureByIndex(); const std::vector<VideoBackendInfo> backends = cv::videoio_registry::getAvailableBackends_CaptureByIndex();
for (size_t i = 0; i < backends.size(); i++) for (size_t i = 0; i < backends.size(); i++)
{ {
...@@ -148,20 +146,6 @@ bool VideoCapture::open(int cameraNum, int apiPreference) ...@@ -148,20 +146,6 @@ bool VideoCapture::open(int cameraNum, int apiPreference)
return false; return false;
} }
bool VideoCapture::open(int index)
{
CV_TRACE_FUNCTION();
// interpret preferred interface (0 = autodetect)
int backendID = (index / 100) * 100;
if (backendID)
{
index %= 100;
}
return open(index, backendID);
}
bool VideoCapture::isOpened() const bool VideoCapture::isOpened() const
{ {
if (!icap.empty()) if (!icap.empty())
...@@ -268,7 +252,7 @@ VideoCapture& VideoCapture::operator >> (UMat& image) ...@@ -268,7 +252,7 @@ VideoCapture& VideoCapture::operator >> (UMat& image)
bool VideoCapture::set(int propId, double value) bool VideoCapture::set(int propId, double value)
{ {
CV_CheckNE(propId, (int)CAP_PROP_BACKEND, "Can set read-only property"); CV_CheckNE(propId, (int)CAP_PROP_BACKEND, "Can't set read-only property");
if (!icap.empty()) if (!icap.empty())
return icap->setProperty(propId, value); return icap->setProperty(propId, value);
...@@ -367,7 +351,7 @@ bool VideoWriter::isOpened() const ...@@ -367,7 +351,7 @@ bool VideoWriter::isOpened() const
bool VideoWriter::set(int propId, double value) bool VideoWriter::set(int propId, double value)
{ {
CV_CheckNE(propId, (int)CAP_PROP_BACKEND, "Can set read-only property"); CV_CheckNE(propId, (int)CAP_PROP_BACKEND, "Can't set read-only property");
if (!iwriter.empty()) if (!iwriter.empty())
return iwriter->setProperty(propId, value); return iwriter->setProperty(propId, value);
...@@ -403,7 +387,7 @@ String VideoWriter::getBackendName() const ...@@ -403,7 +387,7 @@ String VideoWriter::getBackendName() const
return cv::videoio_registry::getBackendName((VideoCaptureAPIs)api); return cv::videoio_registry::getBackendName((VideoCaptureAPIs)api);
} }
void VideoWriter::write(const Mat& image) void VideoWriter::write(InputArray image)
{ {
CV_INSTRUMENT_REGION(); CV_INSTRUMENT_REGION();
...@@ -411,7 +395,7 @@ void VideoWriter::write(const Mat& image) ...@@ -411,7 +395,7 @@ void VideoWriter::write(const Mat& image)
iwriter->write(image); iwriter->write(image);
else else
{ {
IplImage _img = cvIplImage(image); IplImage _img = cvIplImage(image.getMat());
cvWriteFrame(writer, &_img); cvWriteFrame(writer, &_img);
} }
} }
...@@ -424,6 +408,13 @@ VideoWriter& VideoWriter::operator << (const Mat& image) ...@@ -424,6 +408,13 @@ VideoWriter& VideoWriter::operator << (const Mat& image)
return *this; return *this;
} }
VideoWriter& VideoWriter::operator << (const UMat& image)
{
CV_INSTRUMENT_REGION();
write(image);
return *this;
}
// FIXIT OpenCV 4.0: make inline // FIXIT OpenCV 4.0: make inline
int VideoWriter::fourcc(char c1, char c2, char c3, char c4) int VideoWriter::fourcc(char c1, char c2, char c3, char c4)
{ {
......
...@@ -64,7 +64,7 @@ int main(int argc, char** argv) ...@@ -64,7 +64,7 @@ int main(int argc, char** argv)
"{ v video | ../data/vtest.avi | use video as input }" "{ v video | ../data/vtest.avi | use video as input }"
"{ g gray | | convert image to gray one or not}" "{ g gray | | convert image to gray one or not}"
"{ s scale | 1.0 | resize the image before detect}" "{ s scale | 1.0 | resize the image before detect}"
"{ o output | | specify output path when input is images}"; "{ o output | output.avi | specify output path when input is images}";
CommandLineParser cmd(argc, argv, keys); CommandLineParser cmd(argc, argv, keys);
if (cmd.has("help")) if (cmd.has("help"))
{ {
...@@ -175,8 +175,7 @@ void App::run() ...@@ -175,8 +175,7 @@ void App::run()
throw runtime_error(string("can't open image file: " + img_source)); throw runtime_error(string("can't open image file: " + img_source));
} }
UMat img_aux, img; UMat img_aux, img, img_to_show;
Mat img_to_show;
// Iterate over all frames // Iterate over all frames
while (running && !frame.empty()) while (running && !frame.empty())
...@@ -209,8 +208,7 @@ void App::run() ...@@ -209,8 +208,7 @@ void App::run()
// Draw positive classified windows // Draw positive classified windows
for (size_t i = 0; i < found.size(); i++) for (size_t i = 0; i < found.size(); i++)
{ {
Rect r = found[i]; rectangle(img_to_show, found[i], Scalar(0, 255, 0), 3);
rectangle(img_to_show, r.tl(), r.br(), Scalar(0, 255, 0), 3);
} }
putText(img_to_show, ocl::useOpenCL() ? "Mode: OpenCL" : "Mode: CPU", Point(5, 25), FONT_HERSHEY_SIMPLEX, 1., Scalar(255, 100, 0), 2); putText(img_to_show, ocl::useOpenCL() ? "Mode: OpenCL" : "Mode: CPU", Point(5, 25), FONT_HERSHEY_SIMPLEX, 1., Scalar(255, 100, 0), 2);
...@@ -241,7 +239,7 @@ void App::run() ...@@ -241,7 +239,7 @@ void App::run()
if (make_gray) cvtColor(img_to_show, img, COLOR_GRAY2BGR); if (make_gray) cvtColor(img_to_show, img, COLOR_GRAY2BGR);
else cvtColor(img_to_show, img, COLOR_BGRA2BGR); else cvtColor(img_to_show, img, COLOR_BGRA2BGR);
video_writer << img.getMat(ACCESS_READ); video_writer << img;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment