noise in webcam frames Python + Opencv - python

I'm using Opencv 2.4.5 with python 2.7 to track people in video surveillance. At the beginning I used .avi and .mpeg videos to test my code, now I want to use a hcv-m100c camera. I am using a simple difference between frames (an initial frame compared with each frame) to identify the objects in movement, It works very well with the .avi and .mpeg videos I have, but when I use the camera the results are so bad because a lot of noise and stains appear in my video. I thought that the problem was my camera, but I made an .avi video with the same camera and I tested that video with my code and it works fine.
Now, I'm using the cv2.BackgroundSubtractorMOG but the problem is still there.
So, I think I need to do a pre-processing when I use the camera

Just for completeness:
Solution concept:
Possibly you could stream the video camera with something like ffmpeg which can transcode as well and then use OpenCV to read the network stream. It might be easier to use VLC to stream instead.
Solution detail:
VLC Stream code (Shell):
vlc "http://192.168.180.60:82/videostream.cgi?user=admin&pwd=" --sout "#transcode{vcodec=mp2v,vb=800,scale=1,acodec=mpga,ab=128,channels=2,samplerate=??44100}:duplicate{dst=rtp{sdp=rtsp://:8554/output.mpeg},dst=display}" --sout-keep
OpenCV Code (Python):
cap=cv2.VideoCapture("rtsp://:8554/output.mpeg")

Related

Why couldn't OpenCV 3 read the video frames although OpenCV 4 could read?

I have a problem about video reading in Python OpenCV. Although I searched it, I could not find the reason.
I have a bunch of videos that I need to get the frames to process them. It worked for almost all videos. However, I got errors in only four videos. When I tried to run my code with OpenCV 3.4.2 the VideoCapture.read() returned False (ret in the below code), although video_stream.get(cv2.CAP_PROP_FPS) line returned the FPS without problem. However, when I tried the same code with the same four videos using OpenCV 4.2.0, it returned True and was able to read the frames. Here is my code which is a simple video reading code:
video_stream = cv2.VideoCapture(video_path)
fps = video_stream.get(cv2.CAP_PROP_FPS)
ret, frame = video_stream.read()
The videos were recorded by the same device. The video codec is H.264 for all of them and the resolutions are also the same; 1920 x 1080.

How to change the resolution of PS5 camera in OpenCV?

I am trying to change the resolution of PS5 camera in OpenCV, Python.
The problem is that PS5 Camera officially isn't supported on PC, and I have to use custom camera drivers from GitHub: https://github.com/Hackinside/PS5_camera_files
Default image resolution by this code is 640x376
self.capture = cv2.VideoCapture(name)
I found out that supported resolutions of this camera are 640x376 and 5148×1088, so I tried to do next:
res = self.capture.set(cv2.CAP_PROP_FRAME_WIDTH, 5148)
res = self.capture.set(cv2.CAP_PROP_FRAME_HEIGHT, 1088)
But in both cases res is False, and resolution doesn't change. I can recieve only small resolution frame.
Camera 100% can work in 5148×1088, because if I launch Windows Camera application it shows me high quality images
Okay, the problem was, that I had a piece of code, where I read a frame from the capture using a loop:
while True:
self.capture.read()
It was in a parallel thread so changing the resolution was at the same time as reading images. It was a reason why the change resolution process always failed.
So the provided code in question should work if you do it before starting reading images.

How to take still images in python? (Other than opencv CaptureVideo)

I would like to take pictures using the USB webcam. When I use the VideoCapture method of OpenCV, it actually gives frames from the video. In most cases, still images cover more area than the video. Therefore, I am looking for a way to take pictures using the webcam which cover more of the available camera FOV.

Real-time screen capture and feature detection using OpenCV

I successfully processed a video and had the algorithm detect faces, but I am attempting to detect faces in real-time, capturing images from the screen (such as when I'm playing games, etc.) This is the bit of the code I used to process a captured video:
capture = cv2.VideoCapture('source_video.avi')
How can I change this to capture images from the screen in real-time? Please give me some code examples if possible.
Don't use openCV for this. Better use
from PIL import ImageGrab
ImageGrab.grab().save("screen_capture.jpg", "JPEG")

The simplest video streaming?

I have a camera that is taking pictures one by one (about 10 pictures per second) and sending them to PC. I need to show this incoming sequence of images as a live video in PC.
Is it enough just to use some Python GUI framework, create a control that will hold a single image and just change the image in the control very fast?
Or would that be just lame? Should I use some sort of video streaming library? If yes, what do you recommend?
Or would that be just lame?
No. It wouldn't work at all.
There's a trick to getting video to work. Apple's QuickTime implements that trick. So does a bunch of Microsoft product. Plus some open source video playback tools.
There are several closely-related tricks, all of which are a huge pain in the neck.
Compression. Full-sized video is Huge. Do the math 640x480x24-bit color at 30 frames per second. It adds up quickly. Without compression, you can't read it in fast enough.
Buffering and Timing. Sometimes the data rates and frame rates don't align well. You need a buffer of ready-to-display frames and you need a deadly accurate clock to get them do display at exactly the right intervals.
Making a sequence of JPEG images into a movie is what iPhoto and iMovie are for.
Usually, what we do is create the video file from the image and play the video file through a standard video player. Making a QuickTime movie or Flash movie from images isn't that hard. There are a lot of tools to help make movies from images. Almost any photo management solution can create a slide show and save it as a movie in some standard format.
Indeed, I think that Graphic Converter can do this.

Categories