diff --git a/ROADMAP.md b/ROADMAP.md index ce8ad0f2..e821b09e 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -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** diff --git a/videoio.cpp b/videoio.cpp index 4be600e1..e53bc281 100644 --- a/videoio.cpp +++ b/videoio.cpp @@ -1,3 +1,4 @@ +#include #include "videoio.h" // VideoWriter @@ -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 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 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 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 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)); +} diff --git a/videoio.go b/videoio.go index c14089b3..b18df3f1 100644 --- a/videoio.go +++ b/videoio.go @@ -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) +} diff --git a/videoio.h b/videoio.h index 2dd1c109..e3281457 100644 --- a/videoio.h +++ b/videoio.h @@ -3,6 +3,7 @@ #ifdef __cplusplus #include +#include extern "C" { #endif @@ -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 diff --git a/videoio_test.go b/videoio_test.go index 34002bc1..90ce0d0c 100644 --- a/videoio_test.go +++ b/videoio_test.go @@ -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) + } + } + +}