OpenCV doesn’t open the video stream

When I try to open a video capture on my webcam, it doesn’t open it. This is my code:

#include <stdio.h>
#include <opencv2/opencv.hpp>
#include "opencv2/objdetect.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
#include <iostream>
#include "C:/Users/lucal/OneDrive/Dokumente/libraries/simple-serial-port/SimpleSerial.h"
#include <Mmsystem.h>
#include <mciapi.h>
#include <random>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <chrono>
#include <thread>
#include <time.h>
#include <fstream>
#pragma comment(lib, "Winmm.lib")

using namespace std;
using namespace cv;

int detectFace(Mat frame);
void playGenericVoiceLine();
CascadeClassifier face_cascade;
random_device rd;

int main(int argc, const char** argv) {
    String face_cascade_name = "C:/Users/lucal/OneDrive/Dokumente/libraries/opencv/sources/data/haarcascades/haarcascade_frontalface_alt.xml";
    if (!face_cascade.load(face_cascade_name)) {
        cout << "Error loading face cascaden";
        return(-1);
    };
    VideoCapture capture;
    capture.open(0);
    if ( ! capture.isOpened()) {
        cout << "Error opening video capturen";
        return -1;
    }
    Mat frame;

    while (true) {
        capture.read(frame);
        if( frame.empty()) {
            cout << "Error capturing framen";
        }

        int facesOnFrame = detectFace(frame);
    if (facesOnFrame != 0) {
        // playGenericVoiceLine();
        int originalFaceCount = facesOnFrame;
        while (facesOnFrame == originalFaceCount) {
            capture.read(frame);
            if( frame.empty()) {
                cout << "Error capturing framen";
            }
            int facesOnFrame = detectFace(frame);
        }
    };
        if (waitKey(10) == 'q') {
            break;
        }
    }
    return(0);
}

int detectFace(Mat frame) {
    Mat frame_gray;
    cvtColor(frame, frame_gray, COLOR_BGR2GRAY);
    equalizeHist(frame_gray, frame_gray);

    vector<Rect> faces;
    face_cascade.detectMultiScale(frame_gray, faces);
    if( faces.size() != 0) {
        for ( size_t i = 0; i < faces.size(); i++ ) {
            Point center( faces[i].x + faces[i].width/2, faces[i].y + faces[i].height/2 );
            ellipse( frame, center, Size( faces[i].width/2, faces[i].height/2 ), 0, 0, 360, Scalar( 255, 0, 255 ), 4 );
            }
        return int(faces.size());
    }
    else {
        return 0;
    }
}


void playGenericVoiceLine() {
    uniform_int_distribution<int> dist(1,1);
    int randomVoiceLine = dist(rd);
    char com_port[] = "\\.\COM3";
    DWORD COM_BAUD_RATE = CBR_9600;
    SimpleSerial Serial(com_port, COM_BAUD_RATE);

    if( ! Serial.IsConnected()) {
        cout << "Error finding the Arduinon";
    }
    if(Serial.IsConnected()) {
        bool is_sent = Serial.WriteSerialPort("J");
        if( ! is_sent) {
            cout << "Error sending message to the Arduinon";
        }
        }
    string file_name = to_string(randomVoiceLine) + ".mp3";
    string command = "open "" + file_name + "" type mpegvideo alias voiceLine";
    mciSendString(command.c_str(), NULL, 0, NULL);
    mciSendString("play voiceLine wait", NULL, 0, NULL);
    mciSendString("close voiceLine", NULL, 0, NULL);
    bool is_sent = Serial.WriteSerialPort("V");
    if( ! is_sent) {
            cout << "Error sending message to the Arduinon";
    }
}

I declare to open the video capture of the camera 0, but when running the code it doesn’t open a new window with the capture, am I doing something wrong in the code. When running the code I get this terminal message:

PS C:UserslucalOneDriveDesktopradbuildDebug> ."C:/Users/lucal/OneDrive/Desktop/rad/build/Debug/rad.exe"
[ INFO:[email protected]] global videoio_registry.cpp:244 cv::`anonymous-namespace'::VideoBackendRegistry::VideoBackendRegistry VIDEOIO: Enabled backends(9, sorted by priority): FFMPEG(1000); GSTREAMER(990); INTEL_MFX(980); MSMF(970); DSHOW(960); CV_IMAGES(950); CV_MJPEG(940); UEYE(930); OBSENSOR(920)    
[ INFO:[email protected]] global backend_plugin.cpp:383 cv::impl::getPluginCandidates Found 2 plugin(s) for GSTREAMER
[ INFO:[email protected]] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load C:UserslucalOneDriveDokumentelibrariesopencvbuildx64vc16binopencv_videoio_gstreamer490_64d.dll => FAILED
[ INFO:[email protected]] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load opencv_videoio_gstreamer490_64d.dll => FAILED       
[ INFO:[email protected]] global backend_plugin.cpp:383 cv::impl::getPluginCandidates Found 2 plugin(s) for MSMF
[ INFO:[email protected]] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load C:UserslucalOneDriveDokumentelibrariesopencvbuildx64vc16binopencv_videoio_msmf490_64d.dll => OK
[ INFO:[email protected]] global backend_plugin.cpp:50 cv::impl::PluginBackend::initCaptureAPI Found entry: 'opencv_videoio_capture_plugin_init_v1'
[ INFO:[email protected]] global backend_plugin.cpp:169 cv::impl::PluginBackend::checkCompatibility Video I/O: initialized 'Microsoft Media Foundation OpenCV 
Video I/O plugin': built with OpenCV 4.9 (ABI/API = 1/1), current OpenCV version is '4.9.0' (ABI/API = 1/1)
[ INFO:[email protected]] global backend_plugin.cpp:69 cv::impl::PluginBackend::initCaptureAPI Video I/O: plugin is ready to use 'Microsoft Media Foundation OpenCV Video I/O plugin'
[ INFO:[email protected]] global backend_plugin.cpp:84 cv::impl::PluginBackend::initWriterAPI Found entry: 'opencv_videoio_writer_plugin_init_v1'
[ INFO:[email protected]] global backend_plugin.cpp:169 cv::impl::PluginBackend::checkCompatibility Video I/O: initialized 'Microsoft Media Foundation OpenCV 
Video I/O plugin': built with OpenCV 4.9 (ABI/API = 1/1), current OpenCV version is '4.9.0' (ABI/API = 1/1)
[ INFO:[email protected]] global backend_plugin.cpp:103 cv::impl::PluginBackend::initWriterAPI Video I/O: plugin is ready to use 'Microsoft Media Foundation OpenCV Video I/O plugin'
[ INFO:[email protected]] global cap_msmf.cpp:1031 CvCapture_MSMF::configureHW MSMF: Using D3D11 video acceleration on GPU device: AMD Radeon(TM) Vega 8 Graphics
[ INFO:[email protected]] global registry_parallel.impl.hpp:96 cv::parallel::ParallelBackendRegistry::ParallelBackendRegistry core(parallel): Enabled backends(3, sorted by priority): ONETBB(1000); TBB(990); OPENMP(980)
[ INFO:[email protected]] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load C:UserslucalOneDriveDokumentelibrariesopencvbuildx64vc16binopencv_core_parallel_onetbb490_64d.dll => FAILED
[ INFO:[email protected]] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load opencv_core_parallel_onetbb490_64d.dll => FAILED    
[ INFO:[email protected]] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load C:UserslucalOneDriveDokumentelibrariesopencvbuildx64vc16binopencv_core_parallel_tbb490_64d.dll => FAILED
[ INFO:[email protected]] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load opencv_core_parallel_tbb490_64d.dll => FAILED       
[ INFO:[email protected]] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load C:UserslucalOneDriveDokumentelibrariesopencvbuildx64vc16binopencv_core_parallel_openmp490_64d.dll => FAILED
[ INFO:[email protected]] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load opencv_core_parallel_openmp490_64d.dll => FAILED    
[ INFO:[email protected]] global ocl.cpp:1185 cv::ocl::haveOpenCL Initialize OpenCL runtime...
[ INFO:[email protected]] global ocl.cpp:1191 cv::ocl::haveOpenCL OpenCL: found 1 platforms
[ INFO:[email protected]] global ocl.cpp:983 cv::ocl::OpenCLExecutionContext::Impl::getInitializedExecutionContext OpenCL: initializing thread execution context
[ INFO:[email protected]] global ocl.cpp:993 cv::ocl::OpenCLExecutionContext::Impl::getInitializedExecutionContext OpenCL: creating new execution context...  
[ INFO:[email protected]] global ocl.cpp:1011 cv::ocl::OpenCLExecutionContext::Impl::getInitializedExecutionContext OpenCL: device=gfx902
[ INFO:[email protected]] global ocl.cpp:5369 cv::ocl::Context::Impl::__init_buffer_pools OpenCL: Initializing buffer pool for context@0 with max capacity: poolSize=0 poolSizeHostPtr=0
[ INFO:[email protected]] global registry.impl.hpp:114 cv::highgui_backend::UIBackendRegistry::UIBackendRegistry UI: Enabled backends(4, sorted by priority): 
GTK(1000); GTK3(990); GTK2(980); WIN32(970) + BUILTIN(WIN32UI)
[ INFO:[email protected]] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load C:UserslucalOneDriveDokumentelibrariesopencvbuildx64vc16binopencv_highgui_gtk490_64.dll => FAILED
[ INFO:[email protected]] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load opencv_highgui_gtk490_64.dll => FAILED
[ INFO:[email protected]] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load C:UserslucalOneDriveDokumentelibrariesopencvbuildx64vc16binopencv_highgui_gtk3490_64.dll => FAILED
[ INFO:[email protected]] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load opencv_highgui_gtk3490_64.dll => FAILED
[ INFO:[email protected]] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load C:UserslucalOneDriveDokumentelibrariesopencvbuildx64vc16binopencv_highgui_gtk2490_64.dll => FAILED
[ INFO:[email protected]] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load opencv_highgui_gtk2490_64.dll => FAILED
[ INFO:[email protected]] global backend.cpp:90 cv::highgui_backend::createUIBackend UI: using backend: WIN32 (priority=970)

I was expecting my code to open a new window with the capture of the webcam and draw a circle around any facces. I tried downloading gstreamer online but didn#t find anything, I#ve already tried deleting and rebuilding my build files. This is my CmakeLists.txt file:

cmake_minimum_required(VERSION 3.10)
project(rad)

find_package(OpenCV REQUIRED)

include_directories(${OpenCV_INCLUDE_DIRS})
include_directories(C:/libraries/simple-serial-port)  

add_executable(${PROJECT_NAME} src/Main.cpp C:/libraries/simple-serial-port/SimpleSerial.cpp) 

target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS})

New contributor

FireLuc33 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật