Skip to content

add video capture parameters #19394

Merged
alalek merged 3 commits intoopencv:masterfrom
MaximMilashchenko:params
Jan 27, 2021
Merged

add video capture parameters #19394
alalek merged 3 commits intoopencv:masterfrom
MaximMilashchenko:params

Conversation

@MaximMilashchenko
Copy link
Copy Markdown
Contributor

@MaximMilashchenko MaximMilashchenko commented Jan 25, 2021

relates #16766

@alalek , @mshabunin , @allnes

Xforce_builders_only=linux,mac,docs

}

virtual bool open(int);
virtual bool open(int, const cv::VideoCaptureParameters&);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets avoid modification of all backends implementation.
Use virtual function of base class instead.

Modify 1-2 backend which are interested and can be used as sample.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add the open(..., const cv :: VideoCaptureParameters &) function to the base class and implement it only in the required backends (example: gstreamer, msmf)?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes.

Also check similar patch for VideoWriter from here: #16766

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still don't get it. Do you mean that you need to take all the open () to the top in the base class? Can you tell us more about your idea. When implementing the parameters of the video writer, the implementation of the open () function and the extraction of parameters remains at the backend level.

Copy link
Copy Markdown
Member

@alalek alalek Jan 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add common base class method:

bool CvCapture::open(int idx, const cv::VideoCaptureParameters& params)
{
    bool res = open(idx);
    if (res && !params.empty())
    {
        res &= setParameters(params);
        if (!res)
            close();
    }
    return res;
}

Derived classes which don't care about new API don't redefine this method.

Only FFmpeg / GStreamer / MSMF backends may have such method as an example (but do not bring large functionality there - it is not in scope of this PR). If you don't understand then don't add this overload except base classes.

@alalek
Copy link
Copy Markdown
Member

alalek commented Jan 25, 2021

Merge branch 'master'

Avoid such merge commits in PRs. Prefer to keep 1 commit with proper author/e-mail information instead.

Use git rebase -i to maintain that.

Copy link
Copy Markdown
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Current patch has these common mistakes:

  • no tests (especially for new features)
  • massive code changes (which should be avoided): 28 changed files
  • lack of logic for handling of error cases (like silent ignoring of parameters)

/****************** Implementation of interface functions ********************/

Ptr<IVideoCapture> cv::createAndroidCapture_file(const std::string &filename) {
Ptr<IVideoCapture> cv::createAndroidCapture_file(const std::string &filename, const cv::VideoCaptureParameters&) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logic error: We can't just silently ignore parameters.

Copy link
Copy Markdown
Contributor Author

@MaximMilashchenko MaximMilashchenko Jan 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ignore parameters in backends that don't have a open() function or where the base class is CVCapture. Should I add a message about the lack of support for params in this backend? I can also add to the CVCapture the same overload of open functions as in IVideoCapture.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes are dropped.
Fetch latest changes from GitHub with updated handling of such cases.

bool VideoCapture::open(const String& filename, int apiPreference)
{
CV_TRACE_FUNCTION();
return open(filename, apiPreference, std::vector<int> {});
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::vector {}

Just: std::vector<int>()


@overload

Parameters are same as the constructor VideoCapture(const String& filename, int apiPreference = CAP_ANY, bool const std::vector<int>& params)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as the constructor

Where is this constructor?

- add tests
- FFmpeg backend sample code
- StaticBackend API is done
- support through PluginBackend API will be added later
@alalek alalek merged commit 4678704 into opencv:master Jan 27, 2021
@alalek alalek mentioned this pull request Apr 9, 2021
@MaximMilashchenko MaximMilashchenko deleted the params branch November 28, 2021 20:58
a-sajjad72 pushed a commit to a-sajjad72/opencv that referenced this pull request Mar 30, 2023
add video capture parameters

* add parameters

* videoio: revert unnecessary massive changes

* videoio: support capture parameters in backends API

- add tests
- FFmpeg backend sample code
- StaticBackend API is done
- support through PluginBackend API will be added later

Co-authored-by: Milashchenko <maksim.milashchenko@intel.com>
Co-authored-by: Alexander Alekhin <alexander.a.alekhin@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants