I want to change the video resolution from landscape to portrait mode for output from my inbuilt webcam on the laptop (cv2.VideoCapture(0)). I tried rescaling the frames to get it to work, it does go to portrait mode ( height bigger than width) but the video is skewed/stretched. Is there a way around this ? please help. I am using opencv with python.
Welcome to Stackoverflow. What you want to achieve depends on the webcam you use. The Resolution you want need to be supported by your cam. this small tutorial explains it very good.
If your camera does not support the Resolution you want, you have two possibilites:
You Crop the Image to the Resolution you want.
If your max resolution does not allow your resolution you can crop it to the biggest resultion possible with your wanted ratio and after that upscale it.
Careful with upscaling. You have different interpolation methods available.
Related
I found this guide which teaches how to refine the orientation of objects from images. I would love to know if it can and should be used to analyze the orientation of objects displayed in video streams.
The basis for the work is from the scientific publication found in this video. I want to know how they got information about the direction of the Fish's face.
Thanks,
Avishai
You will probably need library like opencv to get orientation information from the image. You can apply threshold after converting this image to grayscale and extract contour of the image. After that you need to follow something like below pattern to get orientation. Very easy, just a little bit search you can find a lot of similar examples as well.
rectangle_for_angle = cv2.minAreaRect(cntrs[0])
angle = rectangle_for_angle[-1]
rect_points = cv2.boxPoints(rectangle_for_angle)
rect_points_result = np.int0(rect_points)
#You can also draw rotated image
cv2.drawContours(image,[rect_points_result],0,(0,0,255),2)
I want to capture 1920x1080 video from my camera but I've run into two issues
When I initialize a VideoCapture, it changes the width/height to 640/480
When I try to change the width/height in cv2, the image becomes messed up
Images
When setting 1920x1080 in cv2, the image becomes blue and has a glitchy bar at the bottom
cap = cv2.VideoCapture('/dev/video0')
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1920)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 1080)
Here's what's happening according to v4l2-ctl. The blue image doesn't seem to be a result of a pixelformat change (eg. RGB to BGR)
And finally, here's an example of an image being captured at 640x480 that has the correct colouring. The only difference in the code is that width/height is not set in cv2
Problem:
Actually the camera you are using has 2 mode:
640x480
1920x1080
One is for main stream, one is for sub stream. I also met this problem couple of times and here is the possible reasons why it doesn't work.
Note: I assume you tried different ways to run on full resolution(1920x1080) such as cv2.VideoCapture(0) , cv2.VideoCapture(-1) , cv2.VideoCapture(1) ...
Possible reasons
First reason could be that the camera doesn't support the resolution you desire but in your case we see that it supports 1920x1080 resolution. So this can not be the reason for your isssue.
Second reason which is general reason is that opencv backend doesn't support your camera driver. Since you are using VideoCaptureProperties of opencv, Documentation says:
Reading / writing properties involves many layers. Some unexpected result might happens along this chain. Effective behaviour depends from device hardware, driver and API Backend.
What you can do:
In this case, if you really need to reach that resolution and make compatible with opencv, you should use the SDK of your camera(if it has).
I have multiple cameras that are closely located to each other, looking at the same scene.
I can calibrate all of them (at once - currently using the openCV algorithm).
What I now want to do is, to overlay for example the following:
Let one camera be a LIDAR depth, the second a grayscale and the third an infrared cam. I want to overlay now the "grayscale scene" in an image format with the depth and infrared information being on the correct pixel. (Similar to depth-grayscale overlays that many 3D-cameras bring).
The cameras have different opening angles and resolutions.
I appreciate any hint or comment :-)
Cheers.
I am trying to extract a subimage from a scanned paper like this:
https://cloud.kopa.ch/index.php/s/gGZm5xeMYlPfU81
The extracted images should be georeferenced and added to a webmap service, but thats not the question here.
How can I get the frame / its pixel coordinates to crop the image?
I am also free in creating the "layout" (similar to the example), which means I could add markers to get the frame better after scanning it again.
The workflow is:
generate layout - print map - draw on the map - scan it - crop "map-frame" - georeferencing this frame - show it on a webmap
The "map-frames" are preprocessed and I know their location/extent
Has anybody an idea how to crop the (scanned) images automatically to this "map-frame"?
I have to work with python and have the packages PIL, pillow and imagemagick for the image processing
Thanks for you help!
If you need more information, don't hesitate to ask
Here's an example I adapted form the Pillow docs, check them out for any further processing that you might need to perform:
from Pillow import Image
Image.open("/path/to/image.jpg")
box = (100, 100, 400, 400)
region = im.crop(box)
Also, it might prove valuable to search Stack Overflow for this kind of operation, I'm sure it has been discussed earlier.
As for finding the actual rectangle to crop you'll have to do some form of image analysis. In it's simplest form, conceptually that could be something along these lines:
Applying an S-curve filter to a black-and-white representation of your image
Iterate over all of the pixels in the image
Keep track of horizontal and vertical lines that has sufficiently black pixel values.
Use this data to determine the bounding box of the portion of the image your interested in.
Depending on your needs you might want to look into some computer vision library instead, which are well optimized for this and similar tasks. The one that springs to mind is OpenCV which is I would guess is well optimized and documented, and there's a python module available as well.
I am using python bindings of openkinect for getting the depth and RGB image. For some reasons , I need the disparity image.
Could someone please help me that how to get that image?
Thanks a lot.
AFAIK you can retrieve different types of image both from the RGB camera (e.g. the IR image) and the depth camera. Don't known exactly which one can be useful for your purposes.
These are the constants for the video camera:
('VIDEO_BAYER',
'VIDEO_IR_10BIT',
'VIDEO_IR_10BIT_PACKED',
'VIDEO_IR_8BIT',
'VIDEO_RGB',
'VIDEO_YUV_RAW',
'VIDEO_YUV_RGB')
and these for the depth camera:
('DEPTH_10BIT',
'DEPTH_10BIT_PACKED',
'DEPTH_11BIT',
'DEPTH_11BIT_PACKED')
For example, to retrieve IR image you can do:
freenect.sync_get_video(0, freenect.VIDEO_IR_10BIT)
working with the non-sync api is analogous. Maybe you could give a try to some of the above video types, sorry I can't be more precise but I lack of some theory behind the kinect.