# cv::VideoCapture with no url or camera index

**URL:** <https://forum.opencv.org/t/cv-videocapture-with-no-url-or-camera-index/6292>\
**Category:** C++\
**Tags:** videoio\
**Created:** [November 18, 2021, 2:40pm UTC](https://forum.opencv.org/t/cv-videocapture-with-no-url-or-camera-index/6292 "2021-11-18T14:40:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![aduq](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/aduq/32/3804_2.png) [@aduq](https://forum.opencv.org/u/aduq)\
**Post date:** [November 18, 2021, 2:40pm UTC](https://forum.opencv.org/t/cv-videocapture-with-no-url-or-camera-index/6292/1 "2021-11-18T14:40:25Z")

</div>

Hey there,

I have some cameras libraries in my project done by me that return a data buffer that afterward is transformed into a cv::Mat object.

Can I use a cv::VideoCapture ptr object to pass the cv::Mat object without having to pass any camera index?

Right now I am testing with cv::imshow that the grabbed image from the buffer works but in the main application my custom frame to show the image.  
Below my testing code

```cpp
while (cv::waitKey(1) != 27) {
    cv::Mat image(m_cr_camera->getHeight(),
                  m_cr_camera->getWidth(), CV_16UC1, m_cr_camera->getBuffer());
    cv::namedWindow(camera_name_window, cv::WINDOW_AUTOSIZE);
    cv::imshow(camera_name_window, image);
  }

```

What I would like to do is something like:

```cpp
cv::VideoCapture *capture = new VideoCapture();
(*capture) >> m_camera->getImage();

```

Then the capture is passed into my custom frame to reproduce the image.  
Thank you in advance.

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [November 18, 2021, 4:18pm UTC](https://forum.opencv.org/t/cv-videocapture-with-no-url-or-camera-index/6292/2 "2021-11-18T16:18:29Z")

</div>

i dont think, what you want is possible (unless you implement another “backend” in the videoio src).  
but at least you could write some “mock” capture class:

```auto
class MyCapture {
    WhatEver *m_cr_camera;
public:
     MyCapture() {
         // init m_cr_camera
     }
     MyCapture& operator >> (Mat& image) {
         image = Mat(m_cr_camera->getHeight(),
                     m_cr_camera->getWidth(), 
                     CV_16UC1, 
                     m_cr_camera->getBuffer()); //.clone(); // (maybe)
         return *this;
     }
};

```

however, you’d have to lookup, ,how data ownership is handled here, if you have to lock the camera, etc.

---

<div class="post-metadata">

**Author:** ![aduq](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/aduq/32/3804_2.png) [@aduq](https://forum.opencv.org/u/aduq)\
**Post date:** [November 18, 2021, 4:46pm UTC](https://forum.opencv.org/t/cv-videocapture-with-no-url-or-camera-index/6292/3 "2021-11-18T16:46:03Z")

</div>

I confirm that you can’t. What I am doing instead is passing by reference my grabbed image after some image processing into the image frame I have using threads.
