當通過WebCamTexture從網絡攝像頭獲取視頻輸入時,返回圖像的最下一行是完全黑色(RGB = 0,0,0)。 我已經嘗試了幾種不同的攝像頭,並獲得與所有這些相同的結果。 使用Windows 10相機應用程序時,以及在Processing或Java中獲取網絡攝像頭Feed時,我的確獲得了正確的圖像。WebCamTexture底部的黑線圖像
在畫布上顯示視頻時,會出現黑線(始終爲1像素高,並且與圖像一樣寬),將快照保存到磁盤以及使用GetPixels32()直接查看像素數據。
這裏是黑線在畫面圖像的底部:
我已經證實,返回的圖像是正確的尺寸,即黑色的行不是一個額外的行。它始終是黑色圖像的最低行。
我已經包含了我在下面使用的c#代碼。
黑線的原因是什麼,有沒有辦法避免它?
我查找過關於這個問題的任何信息,但沒有在網上找到任何東西。我是Unity的初學者,對任何幫助感激不盡。
我使用統一版本5.6.2但與5.5
public class CamController : MonoBehaviour
{
private WebCamTexture webcamTexture;
private WebCamDevice[] devices;
void Start()
{
//start webcam
webcamTexture = new WebCamTexture();
devices = WebCamTexture.devices;
webcamTexture.deviceName = devices[0].name;
webcamTexture.Play();
}
void Update()
{
//if user presses C capture cam image
if (Input.GetKeyDown(KeyCode.C))
captureImage();
}
void captureImage()
{
//get webcam pixels
Color32[] camPixels;
camPixels = webcamTexture.GetPixels32();
//print pixel data for first and second (from bottom) lines of image to console
for (int y = 0; y < 2; y++)
{
Debug.Log("Line: " + y);
for (int x = 0; x < webcamTexture.width; x++)
{
Debug.Log(x + " - " + camPixels[y * webcamTexture.width + x]);
}
}
//save webcam image as png
Texture2D brightBGTexture = new Texture2D(webcamTexture.width, webcamTexture.height);
brightBGTexture.SetPixels32(camPixels, 0);
brightBGTexture.Apply();
byte[] pngBytes = brightBGTexture.EncodeToPNG();
File.WriteAllBytes(Application.dataPath + "/../camImage.png", pngBytes);
}
}
你在'Unity'中使用的'shader'是否顯示來自攝像頭feed的'Texture2D'? – Hristo
我的目標不是顯示攝像頭,而是直接使用圖像像素數據而不顯示圖像。我只顯示用於測試的相機饋送,並且在那時我沒有指定着色器。我在畫布上使用了一個RawImage,並且這個代碼在它上面顯示了攝像頭信息'public RawImage camImage;''camImage.texture = webcamTexture;'我不認爲這是一個陰影問題,因爲黑色像素已經出現在返回的像素數據中通過'GetPixels32()'。 – Torgil