[英]<JAVA> How to take the RGB pixel values of the whole screen in OpenCV
這是我的代碼到目前為止但我得到的錯誤,如OpenCV Error: One of arguments' values is out of range (index is out of range) in cvPtr2D, file ..\\..\\..\\..\\opencv\\modules\\core\\src\\array.cpp, line 1797 Exception in thread "main" java.lang.RuntimeException: ..\\..\\..\\..\\opencv\\modules\\core\\src\\array.cpp:1797: error: (-211) index is out of range in function cvPtr2D
對於如何解決這個問題,有任何的建議嗎? 任何幫助表示贊賞;)
cvNamedWindow("OpenCV", 0);
while(true)
{
IplImage img = cvQueryFrame(cvCreateCameraCapture(0));
CvScalar[] s = new CvScalar[img.height()*img.width()+2];
for(int i = 0;i<=img.width();i++)
{
for(int j = 0;j<=img.height();j++)
{
s[j] = cvGet2D(img, i, j);
}
}
cvShowImage("OpenCV", img);
cvWaitKey(33);
}
cvGet2D()
期望列前的行。 並且索引是從0開始的,所以你的循環只是超出范圍。 s
應該是一個2D數組,所以你不要一直覆蓋你的數據。 嘗試這個:
CvScalar[][] s = new CvScalar[img.height()][img.width()];
for (int i = 0; i < img.height(); i++) {
for (int j = 0; j < img.width(); j++) {
s[i][j] = cvGet2D(img, i, j);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.