mercredi 9 avril 2014

Flash - AS3 - Webcam vidéo dimensions ne pas report à nouveau BitmapData - valeur par défaut de 320 x 240 - Stack Overflow


I am attempting to capture a 1920x1080 webcam capture and create a new bitmap with the capture. I feel like I have all the dimension settings correct but the final 1920x1080 bitmap only contains a small 320x240 version of the video capture. Help!


import flash.display.Bitmap;
import flash.display.BitmapData;

var bandwidth:int = 1000; // Maximum amount of bandwidth that the current outgoing video feed can use, in bytes per second.
var quality:int = 100; // This value is 0-100 with 1 being the lowest quality.

var cam:Camera = Camera.getCamera();
cam.setQuality(bandwidth, quality);
cam.setMode(1920,1080,60,true); // setMode(videoWidth, videoHeight, video fps, favor area)
var video:Video = new Video();
video.attachCamera(cam);
video.x = 0;
video.y = -100;
video.width = 1920;
video.height = 1080;
addChild(video);

var bitmapData:BitmapData = new BitmapData(video.width, video.height);

var bitmap:Bitmap = new Bitmap(bitmapData);
bitmap.x = 0;
bitmap.y = 0;
bitmap.width = 1920;
bitmap.height = 1080;
addChild(bitmap);
bitmap.visible = false;

capture_mc.buttonMode = true;
capture_mc.addEventListener(MouseEvent.CLICK,captureImage);

function captureImage(e:MouseEvent):void {
bitmapData.draw(video);
bitmap.visible = true;
}



I struggled with an almost identical issue for a while. The bitmap image was the desired size, but the photo itself only took up a third of the space within the bitmap image - leaving lots of white space around it.


Hopefully someone can suggest a better solution, but here's what I did to work around it:


var trans:Matrix = new Matrix();
trans.scale(3, 3);
bitmapData.draw(v, trans );

I would suggest for your example, change the scale from 3 to 1920/320.


Another tip: after setting the camera mode, try tracing the camera height and width. This will tell you how many pixels are actually being captured. For example, in my project I tried setting the following settings:


c.setMode(2048, 1536, 5, true);
trace (c.width, c.height, "cam res");

(where c = the camera) The output was "960 720 cam res" - suggesting that this was the maximum resolution my camera could handle, rather than the desired 2048 by 1536


The resultant picture wasn't pixelated, but it wasn't quite as good as pictures captured by the native software. Not sure if this was because of my method or the JPGEnocoder I used to compress the bitmap data.


Also (and I might be wrong about this) - but it might be worth trying:


c.setQuality(0,100);

thus making the bandwidth not a consideration, and putting the emphasis on the quality.




Try lowering your Frames per second, instead of


cam.setMode(1920,1080,60,true); //60 FPS

try


cam.setMode(1920,1080,10,true); //10 FPS

You don't need 60 fps if all you are doing is taking a snapshot


There is also the possibility that your webcam might not support 1920x1080. Maybe try smaller sizes as well if changing FPS doesn't help.



I am attempting to capture a 1920x1080 webcam capture and create a new bitmap with the capture. I feel like I have all the dimension settings correct but the final 1920x1080 bitmap only contains a small 320x240 version of the video capture. Help!


import flash.display.Bitmap;
import flash.display.BitmapData;

var bandwidth:int = 1000; // Maximum amount of bandwidth that the current outgoing video feed can use, in bytes per second.
var quality:int = 100; // This value is 0-100 with 1 being the lowest quality.

var cam:Camera = Camera.getCamera();
cam.setQuality(bandwidth, quality);
cam.setMode(1920,1080,60,true); // setMode(videoWidth, videoHeight, video fps, favor area)
var video:Video = new Video();
video.attachCamera(cam);
video.x = 0;
video.y = -100;
video.width = 1920;
video.height = 1080;
addChild(video);

var bitmapData:BitmapData = new BitmapData(video.width, video.height);

var bitmap:Bitmap = new Bitmap(bitmapData);
bitmap.x = 0;
bitmap.y = 0;
bitmap.width = 1920;
bitmap.height = 1080;
addChild(bitmap);
bitmap.visible = false;

capture_mc.buttonMode = true;
capture_mc.addEventListener(MouseEvent.CLICK,captureImage);

function captureImage(e:MouseEvent):void {
bitmapData.draw(video);
bitmap.visible = true;
}


I struggled with an almost identical issue for a while. The bitmap image was the desired size, but the photo itself only took up a third of the space within the bitmap image - leaving lots of white space around it.


Hopefully someone can suggest a better solution, but here's what I did to work around it:


var trans:Matrix = new Matrix();
trans.scale(3, 3);
bitmapData.draw(v, trans );

I would suggest for your example, change the scale from 3 to 1920/320.


Another tip: after setting the camera mode, try tracing the camera height and width. This will tell you how many pixels are actually being captured. For example, in my project I tried setting the following settings:


c.setMode(2048, 1536, 5, true);
trace (c.width, c.height, "cam res");

(where c = the camera) The output was "960 720 cam res" - suggesting that this was the maximum resolution my camera could handle, rather than the desired 2048 by 1536


The resultant picture wasn't pixelated, but it wasn't quite as good as pictures captured by the native software. Not sure if this was because of my method or the JPGEnocoder I used to compress the bitmap data.


Also (and I might be wrong about this) - but it might be worth trying:


c.setQuality(0,100);

thus making the bandwidth not a consideration, and putting the emphasis on the quality.



Try lowering your Frames per second, instead of


cam.setMode(1920,1080,60,true); //60 FPS

try


cam.setMode(1920,1080,10,true); //10 FPS

You don't need 60 fps if all you are doing is taking a snapshot


There is also the possibility that your webcam might not support 1920x1080. Maybe try smaller sizes as well if changing FPS doesn't help.


0 commentaires:

Enregistrer un commentaire