Skip to content

Commit

Permalink
roadmap: Query I/O API backends registry
Browse files Browse the repository at this point in the history
  • Loading branch information
diegohce committed Oct 3, 2024
1 parent bfb119b commit 66a3d46
Show file tree
Hide file tree
Showing 5 changed files with 327 additions and 11 deletions.
22 changes: 11 additions & 11 deletions ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,17 @@ Your pull requests will be greatly appreciated!

- [X] **imgcodecs. Image file reading and writing.**
- [ ] **videoio. Video I/O - WORK STARTED**
- [ ] Query I/O API backends registry:
- [ ] [getBackendName](https://docs.opencv.org/4.x/de/db1/group__videoio__registry.html#ga6723e68832186e20bd44cd3c2b0d8c60)
- [ ] [getBackends](https://docs.opencv.org/4.x/de/db1/group__videoio__registry.html#ga973abd27c3ea165472f789fa511d9f7b)
- [ ] [getCameraBackendPluginVersion](https://docs.opencv.org/4.x/de/db1/group__videoio__registry.html#gab36e3e19ab2396410b74046de141323c)
- [ ] [getCameraBackends](https://docs.opencv.org/4.x/de/db1/group__videoio__registry.html#ga043347faf6f5590b867a8b621906f7a9)
- [ ] [getStreamBackendPluginVersion](https://docs.opencv.org/4.x/de/db1/group__videoio__registry.html#gadf3c0c355f0917ccf754ac1af79d605a)
- [ ] [getStreamBackends](https://docs.opencv.org/4.x/de/db1/group__videoio__registry.html#ga29296d4c06ed9a9ff8bddae9fe581de1)
- [ ] [getWriterBackendPluginVersion](https://docs.opencv.org/4.x/de/db1/group__videoio__registry.html#gac41a544552a08bf3dc8142d687fbe4e5)
- [ ] [getWriterBackends](https://docs.opencv.org/4.x/de/db1/group__videoio__registry.html#gaed03e49e6a45ca5b20afe1b9f78955e0)
- [ ] [hasBackend](https://docs.opencv.org/4.x/de/db1/group__videoio__registry.html#ga9068310d50ef430c2f5f6b185a99a24b)
- [ ] [isBackendBuiltIn](https://docs.opencv.org/4.x/de/db1/group__videoio__registry.html#gadf24ec0854bb893a75591306ad9f3878)
- [X] Query I/O API backends registry:
- [X] [getBackendName](https://docs.opencv.org/4.x/de/db1/group__videoio__registry.html#ga6723e68832186e20bd44cd3c2b0d8c60)
- [X] [getBackends](https://docs.opencv.org/4.x/de/db1/group__videoio__registry.html#ga973abd27c3ea165472f789fa511d9f7b)
- [X] [getCameraBackendPluginVersion](https://docs.opencv.org/4.x/de/db1/group__videoio__registry.html#gab36e3e19ab2396410b74046de141323c)
- [X] [getCameraBackends](https://docs.opencv.org/4.x/de/db1/group__videoio__registry.html#ga043347faf6f5590b867a8b621906f7a9)
- [X] [getStreamBackendPluginVersion](https://docs.opencv.org/4.x/de/db1/group__videoio__registry.html#gadf3c0c355f0917ccf754ac1af79d605a)
- [X] [getStreamBackends](https://docs.opencv.org/4.x/de/db1/group__videoio__registry.html#ga29296d4c06ed9a9ff8bddae9fe581de1)
- [X] [getWriterBackendPluginVersion](https://docs.opencv.org/4.x/de/db1/group__videoio__registry.html#gac41a544552a08bf3dc8142d687fbe4e5)
- [X] [getWriterBackends](https://docs.opencv.org/4.x/de/db1/group__videoio__registry.html#gaed03e49e6a45ca5b20afe1b9f78955e0)
- [X] [hasBackend](https://docs.opencv.org/4.x/de/db1/group__videoio__registry.html#ga9068310d50ef430c2f5f6b185a99a24b)
- [X] [isBackendBuiltIn](https://docs.opencv.org/4.x/de/db1/group__videoio__registry.html#gadf24ec0854bb893a75591306ad9f3878)

- [X] **highgui. High-level GUI**
- [ ] **video. Video Analysis - WORK STARTED**
Expand Down
98 changes: 98 additions & 0 deletions videoio.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <stdexcept>
#include "videoio.h"

// VideoWriter
Expand Down Expand Up @@ -94,3 +95,100 @@ int VideoWriter_IsOpened(VideoWriter vw) {
void VideoWriter_Write(VideoWriter vw, Mat img) {
*vw << *img;
}

char* Videoio_Registry_GetBackendName(int api) {
cv::String name;

name = cv::videoio_registry::getBackendName((cv::VideoCaptureAPIs)(api));

return strdup(name.c_str());
}

IntVector Videio_Registry_GetBackends() {
IntVector c_backs;

std::vector<cv::VideoCaptureAPIs> backs = cv::videoio_registry::getBackends();

c_backs.val = new int[backs.size()];
c_backs.length = backs.size();

for(int i = 0; i < c_backs.length; i++) {
c_backs.val[i] = backs[i];
}

return c_backs;
}

char* Videoio_Registry_GetCameraBackendPluginVersion(int api, int* version_ABI, int* version_API) {

std::string desc = cv::videoio_registry::getCameraBackendPluginVersion((cv::VideoCaptureAPIs)(api), *version_ABI, *version_API);

return strdup(desc.c_str());
}

IntVector Videoio_Registry_GetCameraBackends() {
IntVector c_backs;

std::vector<cv::VideoCaptureAPIs> backs = cv::videoio_registry::getCameraBackends();

c_backs.val = new int[backs.size()];
c_backs.length = backs.size();

for(int i = 0; i < c_backs.length; i++) {
c_backs.val[i] = backs[i];
}

return c_backs;
}

char* Videoio_Registry_GetStreamBackendPluginVersion(int api, int* version_ABI, int* version_API){

std::string desc = cv::videoio_registry::getStreamBackendPluginVersion((cv::VideoCaptureAPIs)(api), *version_ABI, *version_API);

return strdup(desc.c_str());
}

IntVector Videoio_Registry_GetStreamBackends() {
IntVector c_backs;

std::vector<cv::VideoCaptureAPIs> backs = cv::videoio_registry::getStreamBackends();

c_backs.val = new int[backs.size()];
c_backs.length = backs.size();

for(int i = 0; i < c_backs.length; i++) {
c_backs.val[i] = backs[i];
}

return c_backs;
}

char* Videoio_Registry_GetWriterBackendPluginVersion(int api, int* version_ABI, int* version_API){

std::string desc = cv::videoio_registry::getWriterBackendPluginVersion((cv::VideoCaptureAPIs)(api), *version_ABI, *version_API);

return strdup(desc.c_str());
}

IntVector Videoio_Registry_GetWriterBackends() {
IntVector c_backs;

std::vector<cv::VideoCaptureAPIs> backs = cv::videoio_registry::getWriterBackends();

c_backs.val = new int[backs.size()];
c_backs.length = backs.size();

for(int i = 0; i < c_backs.length; i++) {
c_backs.val[i] = backs[i];
}

return c_backs;
}

bool Videoio_Registry_HasBackend(int api) {
return cv::videoio_registry::hasBackend((cv::VideoCaptureAPIs)(api));
}

bool Videoio_Registry_IsBackendBuiltIn(int api) {
return cv::videoio_registry::isBackendBuiltIn((cv::VideoCaptureAPIs)(api));
}
162 changes: 162 additions & 0 deletions videoio.go
Original file line number Diff line number Diff line change
Expand Up @@ -560,3 +560,165 @@ func OpenVideoCaptureWithAPIParams(v interface{}, apiPreference VideoCaptureAPI,
return nil, errors.New("argument must be int or string")
}
}

type VideoRegistryType struct{}

// VideoRegistry
//
// For further details, please see:
// https://docs.opencv.org/4.x/de/db1/group__videoio__registry.html
var VideoRegistry VideoRegistryType

// GetBackendName Returns backend API name or "UnknownVideoAPI(xxx)".
//
// For further details, please see:
// https://docs.opencv.org/4.x/de/db1/group__videoio__registry.html#ga6723e68832186e20bd44cd3c2b0d8c60
func (VideoRegistryType) GetBackendName(api VideoCaptureAPI) string {

c_name := C.Videoio_Registry_GetBackendName(C.int(api))
defer C.free(unsafe.Pointer(c_name))

name := C.GoString(c_name)
return name
}

// GetBackends Returns list of all available backends.
//
// For further details, please see:
// https://docs.opencv.org/4.x/de/db1/group__videoio__registry.html#ga973abd27c3ea165472f789fa511d9f7b
func (VideoRegistryType) GetBackends() []VideoCaptureAPI {
intVec := C.Videio_Registry_GetBackends()
defer C.IntVector_Close(intVec)

c_ints := unsafe.Slice(intVec.val, int(intVec.length))

ints := make([]VideoCaptureAPI, len(c_ints))

for i, val := range c_ints {
ints[i] = VideoCaptureAPI(int(val))
}
return ints
}

// GetCameraBackendPluginVersion Returns description and ABI/API version of videoio plugin's camera interface.
//
// For further details, please see:
// https://docs.opencv.org/4.x/de/db1/group__videoio__registry.html#gab36e3e19ab2396410b74046de141323c
func (VideoRegistryType) GetCameraBackendPluginVersion(api VideoCaptureAPI) (string, int, int) {
var (
version_abi C.int
version_api C.int
)

c_desc := C.Videoio_Registry_GetCameraBackendPluginVersion(C.int(api), &version_abi, &version_api)
defer C.free(unsafe.Pointer(c_desc))
desc := C.GoString(c_desc)

return desc, int(version_abi), int(version_api)
}

// GetCameraBackends Returns list of available backends which works via gocv.VideoCapture(int index)
//
// For further details, please see:
// https://docs.opencv.org/4.x/de/db1/group__videoio__registry.html#ga043347faf6f5590b867a8b621906f7a9
func (VideoRegistryType) GetCameraBackends() []VideoCaptureAPI {
intVec := C.Videoio_Registry_GetCameraBackends()
defer C.IntVector_Close(intVec)

c_ints := unsafe.Slice(intVec.val, int(intVec.length))

ints := make([]VideoCaptureAPI, len(c_ints))

for i, val := range c_ints {
ints[i] = VideoCaptureAPI(int(val))
}
return ints
}

// GetStreamBackendPluginVersion Returns description and ABI/API version of videoio plugin's stream capture interface
//
// For further details, please see:
// https://docs.opencv.org/4.x/de/db1/group__videoio__registry.html#gadf3c0c355f0917ccf754ac1af79d605a
func (VideoRegistryType) GetStreamBackendPluginVersion(api VideoCaptureAPI) (string, int, int) {
var (
version_abi C.int
version_api C.int
)

c_desc := C.Videoio_Registry_GetStreamBackendPluginVersion(C.int(api), &version_abi, &version_api)
defer C.free(unsafe.Pointer(c_desc))
desc := C.GoString(c_desc)

return desc, int(version_abi), int(version_api)
}

// GetStreamBackends Returns list of available backends which works via gocv.VideoCapture(int index)
//
// For further details, please see:
// https://docs.opencv.org/4.x/de/db1/group__videoio__registry.html#ga29296d4c06ed9a9ff8bddae9fe581de1
func (VideoRegistryType) GetStreamBackends() []VideoCaptureAPI {
intVec := C.Videoio_Registry_GetStreamBackends()
defer C.IntVector_Close(intVec)

c_ints := unsafe.Slice(intVec.val, int(intVec.length))

ints := make([]VideoCaptureAPI, len(c_ints))

for i, val := range c_ints {
ints[i] = VideoCaptureAPI(int(val))
}
return ints
}

// GetWriterBackendPluginVersion Returns description and ABI/API version of videoio plugin's writer interface.
//
// For further details, please see:
// https://docs.opencv.org/4.x/de/db1/group__videoio__registry.html#gac41a544552a08bf3dc8142d687fbe4e5
func (VideoRegistryType) GetWriterBackendPluginVersion(api VideoCaptureAPI) (string, int, int) {
var (
version_abi C.int
version_api C.int
)

c_desc := C.Videoio_Registry_GetWriterBackendPluginVersion(C.int(api), &version_abi, &version_api)
defer C.free(unsafe.Pointer(c_desc))
desc := C.GoString(c_desc)

return desc, int(version_abi), int(version_api)
}

// GetWriterBackends Returns list of available backends which works via gocv.VideoWriter()
//
// For further details, please see:
// https://docs.opencv.org/4.x/de/db1/group__videoio__registry.html#gaed03e49e6a45ca5b20afe1b9f78955e0
func (VideoRegistryType) GetWriterBackends() []VideoCaptureAPI {
intVec := C.Videoio_Registry_GetWriterBackends()
defer C.IntVector_Close(intVec)

c_ints := unsafe.Slice(intVec.val, int(intVec.length))

ints := make([]VideoCaptureAPI, len(c_ints))

for i, val := range c_ints {
ints[i] = VideoCaptureAPI(int(val))
}
return ints
}

// HasBackend Returns true if backend is available.
//
// For further details, please see:
// https://docs.opencv.org/4.x/de/db1/group__videoio__registry.html#ga9068310d50ef430c2f5f6b185a99a24b
func (VideoRegistryType) HasBackend(api VideoCaptureAPI) bool {
b := C.Videoio_Registry_HasBackend(C.int(api))
return bool(b)
}

// IsBackendBuiltIn Returns true if backend is built in (false if backend is used as plugin)
//
// For further details, please see:
// https://docs.opencv.org/4.x/de/db1/group__videoio__registry.html#gadf24ec0854bb893a75591306ad9f3878
func (VideoRegistryType) IsBackendBuiltIn(api VideoCaptureAPI) bool {
b := C.Videoio_Registry_IsBackendBuiltIn(C.int(api))
return bool(b)
}
13 changes: 13 additions & 0 deletions videoio.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#ifdef __cplusplus
#include <opencv2/opencv.hpp>
#include <opencv2/videoio/registry.hpp>
extern "C" {
#endif

Expand Down Expand Up @@ -40,6 +41,18 @@ void VideoWriter_Open(VideoWriter vw, const char* name, const char* codec, doubl
int VideoWriter_IsOpened(VideoWriter vw);
void VideoWriter_Write(VideoWriter vw, Mat img);

//Videoio Query I/O API backends registry
char* Videoio_Registry_GetBackendName(int api);
IntVector Videio_Registry_GetBackends();
char* Videoio_Registry_GetCameraBackendPluginVersion(int api, int* version_ABI, int* version_API);
IntVector Videoio_Registry_GetCameraBackends();
char* Videoio_Registry_GetStreamBackendPluginVersion(int api, int* version_ABI, int* version_API);
IntVector Videoio_Registry_GetStreamBackends();
char* Videoio_Registry_GetWriterBackendPluginVersion(int api, int* version_ABI, int* version_API);
IntVector Videoio_Registry_GetWriterBackends();
bool Videoio_Registry_HasBackend(int api);
bool Videoio_Registry_IsBackendBuiltIn(int api);

#ifdef __cplusplus
}
#endif
Expand Down
43 changes: 43 additions & 0 deletions videoio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,46 @@ func TestVideoCaptureFile_GrabRetrieve(t *testing.T) {
t.Error("Unable to read VideoCaptureFile")
}
}

func TestVideoRegistry(t *testing.T) {

name := VideoRegistry.GetBackendName(VideoCaptureFFmpeg)
t.Log("VideoRegistry.GetBackendName()", name)

backs := VideoRegistry.GetBackends()
for _, b := range backs {
t.Log("VideoRegistry.GetBackends()", b.String())
}

cameraBacks := VideoRegistry.GetCameraBackends()
for _, b := range cameraBacks {
t.Log("VideoRegistry.GetCameraBackends()", b.String())
if !VideoRegistry.IsBackendBuiltIn(b) && VideoRegistry.HasBackend(b) {

description, abiVersion, apiVersion := VideoRegistry.GetCameraBackendPluginVersion(b)
t.Log("VideoRegistry.GetCameraBackendPluginVersion()", description, abiVersion, apiVersion)
}
}

streamBacks := VideoRegistry.GetStreamBackends()
for _, b := range streamBacks {
t.Log("VideoRegistry.GetStreamBackends()", b.String())
if !VideoRegistry.IsBackendBuiltIn(b) && VideoRegistry.HasBackend(b) {

description, abiVersion, apiVersion := VideoRegistry.GetStreamBackendPluginVersion(b)
t.Log("VideoRegistry.GetStreamBackendPluginVersion()", description, abiVersion, apiVersion)
}
}

writerBacks := VideoRegistry.GetWriterBackends()

for _, b := range writerBacks {
t.Log("VideoRegistry.GetWriterBackends()", b.String())
if !VideoRegistry.IsBackendBuiltIn(b) && VideoRegistry.HasBackend(b) {

description, abiVersion, apiVersion := VideoRegistry.GetWriterBackendPluginVersion(b)
t.Log("VideoRegistry.GetWriterBackendPluginVersion()", description, abiVersion, apiVersion)
}
}

}

0 comments on commit 66a3d46

Please sign in to comment.