0

I am trying to use a VideoCapture object in a class , all the examples that i have seen are setting the camera id in the constructor of the object.

cv::VideoCapture cam(1);

if i declare the object as a class variable

 cv::VideoCapture cam

how can i initialize it in the class constructor to camID = 1;

Summit
  • 2,112
  • 2
  • 12
  • 36
  • 1
    Does this answer your question? [What is this weird colon-member (" : ") syntax in the constructor?](https://stackoverflow.com/questions/1711990/what-is-this-weird-colon-member-syntax-in-the-constructor) – JaMiT Aug 27 '20 at 03:29
  • 1
    Call cv::VideoCapture with your class constructor using cam index as parameter – Ziri Aug 27 '20 at 03:34

1 Answers1

2

You can initialize it by using open :

class InitialiseTest
{    
    VideoCapture cap;    
public:
    InitialiseTest(){
        cap.open(1);
    }        
};

int main()
{    
    InitialiseTest obj;
    
}
Yunus Temurlenk
  • 4,085
  • 4
  • 18
  • 39