I want to use video capture card to capture my screen display, and process the image by OpenCV/C++.
I have heard that there's some video capture card which is webcam like.(i.e. I can get the screen display by VideoCapture in OpenCV.)
Can someone tell me which video capture card should I buy?
Thanks !!!
I do not know if there some way to achieve that directly using OpenCV. However, a simple workaround could be like this:
Using this software you can create new webcam that stream your screen: https://sparkosoft.com/how-to-stream-desktop-as-webcam-video
Using OpenCV you can start capture the stream using this code:
cv::VideoCapture cap;
if(!cap.open(0)) // Use the new webcam Id instead of 0
return 0;
while(true){
cv::Mat frame;
cap >> frame;
if(frame.empty()) break;
cv::imshow("Screen", frame);
if( waitKey(10) == 27 ) break;
}
return 0;
I don't know if this helps now. But i found a way using opencv.
In linux and python, we achieve this using the following piece of code.
import cv2
cap = cv2.VideoCapture('/dev/video0')
Related
I am trying to make something like a video player using Python. Quick google search showed me how to play a video using OpenCV. But video rendered using OpenCV is not as crisp as the video played by VLC media player. The images of both players are shown below.
OpenCV rendering
Video in VLC media player
I have checked the width and height of the images rendered by OpenCV and it is 1080p. But somehow the video is not as crisp as it should be. Here is the code used to render the images.
def start_slideshow_demo(video_file_path: str):
cap = cv2.VideoCapture(video_file_path)
cv2.namedWindow(video_file_path, cv2.WINDOW_GUI_EXPANDED)
cv2.setWindowProperty(video_file_path, cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)
while(cap.isOpened()):
ret, frame = cap.read()
if ret == True:
cv2.imshow(video_file_path, frame)
if cv2.waitKey(25) & 0xFF == ord('q'):
break
else:
break
cap.release()
cv2.destroyAllWindows()
Any help is appreciated. Thank you.
i don think it's Opencv issue. I used your code as it is in my desktop.
(left : opencv - right VLC player)
I am trying to read a high resolution video using OpenCV VideoCapture and it seems to be extremely slow. I read somewhere changing the buffer sizes might help, but I tried setting all kinds of buffer sizes and its still slow.
Any help here on what settings can help improve reading high resolution videos for java opencv is really appreciated
I am using VideoCapture to read a video from disk. I am using Mac OSX. Here is a snippet of my code:
while(camera.read(frame))
{
BufferedImage bufferedImage = MatToBufferedImage(frame);
BufferedImage scaledImage = (BufferedImage)getScaledImage(bufferedImage, frameWidth, frameHeight);
ImageIcon icon = new ImageIcon(scaledImage);
publish(icon);
}
I am using swingworker and doing this in the background thread.
I am not explicitly setting any openCV properties. Should I be setting any explicit properties is something I am not sure of.
Here is what I observe: My video starts off well and then around 50th frame or so, i see some lag and then again at around 120th frame and it almost completely stops at frame number 190ish.
Have you tried resizing the individual frames?
while(camera.read(frame))
{
resize(frame,frame,Size(640,360));
imshow("frame",frame);
}
how to make two video run at same time and same fps ?
VideoCapture capture("../video/Success/NT 1.1.wmv");
VideoCapture capture2("../video/Success/NT 1.wmv");
capture.set(CV_CAP_PROP_FPS , 30);
capture2.set(CV_CAP_PROP_FPS , 60);
waitKey(30);
For example, i have this two video and i set the fps for these two videos already but this capture.set(CV_CAP_PROP_FPS , 30) doesn't work for my program..
OpenCV is not a playback library, nor it was ever intended to support such functions. Setting FPS does absolutely nothing there.
The only thing that OpenCV does it to offer you the possibility to extract frames from a video, one after another.
You'll have to devise your own, complete, timing sequences to control the speed at which images are displayed on screen.
Or, better, use VLC.
what is problem in writing very simple code for same fps:
// Open videos
VideoCapture capture("../video/Success/NT 1.1.wmv");
VideoCapture capture2("../video/Success/NT 1.wmv");
Mat frame, frame2;
while(..)
{
capture >> frame;
capture2 >> frame2;
//imSHOW or do anything with these frame..
waitKey(30);
}
//Close video
Am I missing something or you?
I have a analog camera connected to EasyCap video capture device. When I run a basic code which opens webcam video using OPENCV, I can access my in-built webcam but not the other analog camera.
How would you connect any other camera (FPV, IR, etc) to the PC such that OPENCV can access it.
Thanks.
i struggled with the same problem and hope it helps!
the original thread + ANSWER
also relevant XKCD
one more observation: from your description it looks like you already have a webcam running on the laptop (in-built webcam maybe?) you might want to disable it in system manager so as to guarantee that your analog camera cam_index is zero for certain. Otherwise if you leave the webcam enabled as a device, then your analog cam will most likely be incremented to cam_index=1 which amusingly enough seems to be confirmed by it crashing on cam_index=1.
Arguable not a great method to find your camera's index but there you have it!
You can set which camera to connect to open by changing the following deviceID to the desired device you want:
CvCapture* capture = cvCaptureFromCAM(deviceID);
or new API:
VideoCapture cap(deviceID);
Check out documenation for more info.
Use the deviceID of the analog camera instead of the in-built one.
This is probably an open-ended question. I have written an opencv application that captures feed from two external cameras connected to the computer. The capture from both the cameras runs parallely on 2 different threads. This recorder module writes the frames to a video file which is later processed. The following code sits inside each thread function:
CvCapture *capture =cvCaptureFromCAM(indexOfCamera);
if(!capture) return;
CvSize sz =cvGetSize(cvQueryFrame(capture));
cvNamedWindow("src");
CvVideoWriter *writer =cvCreateVideoWriter((char*) p, CV_FOURCC('L','A','G','S'), 20, sz);
if( !writer ) {
cvReleaseCapture( &capture );
return;
}
IplImage *frame;
int frameCounter =0;
while(true){
QueryPerformanceCounter(&sideCamCounter);
frame =cvQueryFrame(capture);
if(!frame)break;
//Store timestamp of frame somewhere
cvShowImage("src", frame);
cvWriteFrame(writer, frame);
int c=cvWaitKey(1);
if((char)c ==27)break;
++frameCounter;
}
cvReleaseVideoWriter(&writer);
cvReleaseCapture(&capture);
cvDestroyAllWindows();
The two cameras I am using are: A - Microsoft hd-6000 lifecam for notebooks and B - Logitech sphere AF webcam. Camera A captures at around 16-20 fps(reaches upto 30 fps during a few recordings) and camera B captures at around 10-12 fps.
I need a faster capture rate to be able to capture real-time motion. I understand I will be limited by the camera's capture speed/rate but apart from that, what other factors will affect the capture rate - e.g. load on the system(Memory and CPU), the API's used ? I am open to explore options. Thanks.
Try to set different camera properties - http://docs.opencv.org/modules/highgui/doc/reading_and_writing_images_and_video.html#videocapture-set, probably the most interesting for you will be... FPS :) Note that it's not always working fine ( How to set camera FPS in OpenCV? CV_CAP_PROP_FPS is a fake ), but give it a chance, maybe it will help you. Also you may try to set smaller image resolution.
If you don't have to - don't display image.
You may try to grab frames in one thread and process in another.
Connect cameras directly to your computer - don't use USB hub.
the API's used
I don't think it will help, but if you want you may try to use different API - OpenCV on Mac is not opening USB web camera