2012-03-09 104 views
1

我對Flash或動作腳本知之甚少,但是我一直對AS3和網絡攝像頭有點麻煩。我有一個連接到攝像頭的腳本,然後將其輸出發送到一個php腳本,以保存捕獲的圖像。除了一個問題,這一切都可以工作。看起來,實際的Camera對象允許的最大分辨率是320x240。我把一臺佳能60D連接到網絡攝像機的極端,因爲我有一個普通的攝像頭,它的最大分辨率應該是1280x720,而我所能得到的是一張320x240的圖像。到目前爲止我發現的是,我可以從佳能獲得的最大值也是320x240。也許我一直在看這個,但我很難過。以下是videoCapture應爲1024x768的動作腳本示例。取而代之的是1024x768圖像是在黑色背景下創建的,左上角是來自videoCapture的320x240圖像。我顯然可以調整這一點,但這會挫敗質量差的目的。有什麼我在這裏失蹤,或者甚至可能是Flash的一些限制?AS3網絡攝像頭分辨率/尺寸問題

// adds event listener to the stage for keydown events. 
stage.addEventListener(KeyboardEvent.KEY_DOWN, detectEnterKey); 

import flash.display.Bitmap; 
import flash.display.BitmapData; 
import com.adobe.images.JPGEncoder; 
import flash.ui.Keyboard; 
import flash.events.KeyboardEvent; 

var bandwidth:int = 0; 
var quality:int = 100; 

var cam:Camera = Camera.getCamera(); 

var videoCapture:Video = new Video(); 

var previewPortData:BitmapData = new BitmapData(1024, 768, true, 0x00000000); 
var previewPort:Bitmap = new Bitmap(previewPortData); 

function onCameraStatus(evt):void { 
    if (evt.code == "Camera.Muted") { 
    Security.showSettings(SecurityPanel.CAMERA); 
    } 
} 

// detects the keycode looking for enter key pressed. 
function detectEnterKey(event:KeyboardEvent):void { 
    //trace("keycode: "+event.keyCode); 
    if (event.keyCode == Keyboard.ENTER) { 
    previewPortData.draw(videoCapture); 
    var myEncoder:JPGEncoder = new JPGEncoder(100); 
    var byteArray:ByteArray = myEncoder.encode(previewPortData); 
    var header:URLRequestHeader = new URLRequestHeader("Content-type", "application/octet-stream"); 
    var saveJPG:URLRequest = new URLRequest("save.php"); 
    saveJPG.requestHeaders.push(header); 
    saveJPG.method = URLRequestMethod.POST; 
    saveJPG.data = byteArray; 
    var urlLoader:URLLoader = new URLLoader(); 
    urlLoader.addEventListener(Event.COMPLETE, sendComplete); 
    urlLoader.load(saveJPG); 

    function sendComplete(event:Event):void { 
     trace("compete"); 
    } 
    } 
} 

if (cam == null) { 

    Security.showSettings(SecurityPanel.CAMERA); 

} else { 

    cam.addEventListener(StatusEvent.STATUS, onCameraStatus) 
    cam.setQuality(bandwidth, quality); 
    cam.setMode(1024, 768, 30, false); 

    videoCapture.attachCamera(cam); 
    videoCapture.width = 1024; 
    videoCapture.height = 768; 
    addChild(videoCapture); 

    previewPort.x = 430; 
    previewPort.y = 50; 
    addChild(previewPort); 

} 
+0

你使用什麼操作系統? – Engineer 2012-03-09 10:22:21

+0

我目前正在使用Windows XP。我沒有機會測試其他任何東西。 – 2012-03-09 11:42:46

+0

我肯定會嘗試其他操作系統,查找更新的驅動程序等。當您執行cam.setMode()並傳遞分辨率時,應該嘗試查找相機支持的最接近的分辨率。我的經驗是,這並不好。嘗試使用320x240和1024x768之間的臨時分辨率來查看是否可以獲得高於320x240的分辨率。 – 2012-04-02 17:29:05

回答

7

我也只是有這個問題。通過在創建Video對象時包含寬度和高度參數來解決它,而不是通過Video.height和Video.width來設置它們。一旦我這樣做,從該視頻採集的所有bitmapData大小都正確。

這是怎麼了我最初創建的沒有工作視頻(看起來很好,但造成了尺寸不正確的位圖):

var vid = new Video(); 
vid.width = 640; 
vid.height = 480; 
... 

這個工作(從這段視頻的位圖是正確的大小):

var vid = new Video(640, 480); 
... 

想知道爲什麼第一種方式不起作用。也許這是上面提到的錯誤。 (我沒有訪問該網站,所以看不到它。)

+0

這適用於我,謝謝。它絕對看起來像一個bug。 http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/Video.html上的官方文檔聲明:「您還可以在初始化後設置Video對象的寬度和高度屬性建設,使用Video.width和Video.height。「這意味着通過構造函數傳遞值應該等同於之後的設置。 – ddso 2013-01-22 14:39:34

1

我有一個類似的問題。什麼工作對我來說是我代替:

previewPortData.draw(videoCapture); 

有了:

previewPortData.draw(stage);