Created
December 11, 2021 16:40
-
-
Save thegabriele97/7bf8c6dd3fca966b504a36b800d44e5e to your computer and use it in GitHub Desktop.
open cv webcam
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <fcntl.h> /* For O_RDWR */ | |
#include <sys/ioctl.h> | |
#include <unistd.h> /* For open(), creat() */ | |
#include <netdb.h> | |
#include <sys/epoll.h> | |
#include <sys/socket.h> | |
#include <unistd.h> | |
#include <signal.h> | |
#include <sys/stat.h> | |
#include <sys/types.h> | |
#include <cuda_runtime.h> | |
#include <device_launch_parameters.h> | |
#include <time.h> | |
#include <stdint.h> | |
#include "opencv2/opencv.hpp" | |
#include <pthread.h> | |
#include "v4l.h" | |
#define NSTREAMS 1 | |
using namespace cv; | |
int main() { | |
VideoCapture cap; | |
if (!cap.open(0, CAP_V4L2)) return 1; | |
cap.set(3, 1920); | |
cap.set(4, 1080); | |
Mat base; | |
cap >> base; | |
namedWindow("hi", WINDOW_GUI_NORMAL); | |
while (1) { | |
auto begin = std::chrono::high_resolution_clock::now(); | |
cap >> base; | |
if (base.empty()) { | |
break; // end of video stream | |
} | |
imshow("hi", base); | |
if (waitKey(10) == 27) { | |
break; // stop capturing by pressing ESC | |
} | |
auto end = std::chrono::high_resolution_clock::now(); | |
auto elaps = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin); | |
printf("\rFPS: %5.2f", 1 / ((float)elaps.count() * 1e-9)); | |
fflush(stdout); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment