Reputation: 139
The project I am currently working on requires me to capture images prior to processing it. I am using a logitech c270 webcam and there are a number of available resolutions for me to choose on. However, none of the available resolutions matches my case as I want to capture square only images but none of the resolutions supported by my webcam are squares and all of them are rectangles only.
For example, I would like to capture a 640x640 image (square) but my webcam could only capture rectangular images (resolutions that are rectangular).
Since there is no way for me to change the supported resolution of the webcam, is there any way for me to set the region of the webcam when previewing it? Let's say I set my default webcam resolution in matlab to 960x720, but when I preview the webcam to my users, I crop out the additional pixels from the sides, and only display 640x640?
I understand that I could crop the image out later, after I have captured the image (in this case, a face of a person), however, cropping the image later would result in the possibility of the face going out of the square region, or larger than the square region. I only wants the person to position himself in the square region from the webcam. Is there any way to set my webcam manually in matlab to perform as such?
Upvotes: 1
Views: 378
Reputation:
After opening a video object say vid
in Matlab, e.g. as
vid = videoinput('winvideo', 1, 'YUY2_960x720');
do the following:
startx = 161; % horizontal starting index
starty = 41; % vertical starting index
width = 640;
height = 640;
uddobj = imaqgate('privateGetField', vid, 'uddobject');
set(uddobj, 'ROIPosition', [startx, starty, width, height]);
preview(vid);
for getting an ROI of the region (41:680, 161:800) according to Matlab index notation.
N.B. This is tested in Matlab R2011a.
Upvotes: 1