MATLAB: Rotate video from camera preview

previewrotatevideo

n Matlab I can get a preview from a camera with the command: preview(obj,himage) that puts the preview stream into himage.
In my code I have an axes that contains the video preview but I would like to rotate the video by 90 degrees. This might be very stupid but I cannot figure out how is done.
My code is the following:
prevHaxes = axes('Parent', mainFig);
previewImage= imagesc(placeholderImg,'Parent', prevHaxes); %Placeholder for when the stream is off
preview(video_obj, previewImage);
I have tried to use imrotate but I got the following error:
"Expected input number 1, input image, to be one of these types:
numeric, logical
Instead its type was matlab.graphics.primitive.Image."
So my question is, is there a way to get the video preview from a camera but to visualize it rotated by an angle?

Best Answer

All right,
found a way and it is posted here for future reference. Assuming "placeholderImg" is the image where the preview will be displayed, it is possible to set a function that will intercept all frames. The function is UpdatePreviewWindowFcn. So before starting the preview, one sets:
setappdata(placeholderImg,'UpdatePreviewWindowFcn',@mypreview_fcn);
and defines mypreview_fcn as
function mypreview_fcn(obj, event, himage)
rotImg = rot90(event.Data);
set(himage, 'cdata', rotImg);
end
That is it.