I write codes for face detection by using webcam, for access the camera I use "initWebcam" function in openCV as the follow:
void initWebcam(VideoCapture &videoCapture, int cameraNumber)
{
try {
videoCapture.open(cameraNumber);
} catch(cv::Exception &e) {}
if(!videoCapture.isOpened()) {
cerr