Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: OpenCV video in SFML window  (Read 2542 times)

0 Members and 1 Guest are viewing this topic.

gosh1k

  • Newbie
  • *
  • Posts: 1
    • View Profile
OpenCV video in SFML window
« on: September 27, 2021, 10:02:40 am »
Help please, I need to display the video that I play using OpenCV in SFML window

#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
#include <SFML/Audio.hpp>
#include <SFML/Config.hpp>
#include <SFML/GpuPreference.hpp>
#include <SFML/Main.hpp>
#include <SFML/OpenGL.hpp>
#include <iostream>
#include <opencv2/opencv.hpp>


using namespace sf;
using namespace std;
using namespace cv;

int main(){
    RenderWindow window(sf::VideoMode(1920, 1080), "War - New Era in 16bit!");
    Image heroimage;
    heroimage.loadFromFile("C:/Users/vitya/source/repos/Project2/Project2/biografiya-glad-valakas.jpg");
    Sprite herosprite;
    Texture herotexture;
    herotexture.loadFromImage(heroimage);
    herosprite.setTexture(herotexture);
    herosprite.setPosition(450,60);
    Music music;
    if (!music.openFromFile("jojo.wav")) {
        cout << "error"; }
    music.play();
    while (window.isOpen()){
        Event event;
        while (window.pollEvent(event))
        {
            if(event.type==Event::Closed)
            window.close();
        }
        window.clear();
        window.draw(herosprite);
        window.display();}
    VideoCapture cap("D:\\1_1.mp4");
    if (cap.isOpened() == false){
        cout << "Cannot open the video file" << endl;
        cin.get();
        return -1;}
    double fps = cap.get(CAP_PROP_FPS);
    cout << "Frames per seconds : " << fps << endl;
    string window_name = "My First Video";
    namedWindow(window_name);
   //setWindowProperty("window name", WND_PROP_FULLSCREEN, WINDOW_FULLSCREEN);
    while (true)
    {
        Mat frame;
        bool bSuccess = cap.read(frame);
        if (bSuccess == false)
        {
            cout << "Found the end of the video" << endl;
        }
        imshow(window_name, frame);
        if (waitKey(10) == 27)
        {
            cout << "Esc key is pressed by user. Stoppig the video" << endl;
        }
    }
    return 0;
}

 

anything