[英]OpenCV Capture from Camera Results in Noisy-like Image
我在嵌入式目標板上使用了OpenCV(FriendlyARM mini6410,運行Linux內核2.6.38的處理器1176)。 我使用為開發板提供的工具鏈編譯了OpenCV 2.4.4庫,可在ftp中找到(請參見FriendlyARM 網站 )。 我禁用了GTK,ffmpeg並啟用了v4l。 該庫已成功編譯。
然后我寫代碼:
#include <opencv.hpp>
#include <highgui/highgui.hpp>
#include <imgproc/imgproc.hpp>
#include <iostream>
#include <stdio.h>
using namespace cv;
using namespace std;
int main()
{
int i;
cout << "initialise" << endl;
IplImage* img=0;
cout << "capturing ..." << endl;
CvCapture* capture = cvCaptureFromCAM(2);
cout << "get here" << endl;
if(!capture){
cout << "not capture" << endl;
return -1;
}
cout << "captured" << endl;
img=cvQueryFrame(capture);
IplImage* img1 = cvCreateImage(cvGetSize(img),8,3);
// cvCvtColor(img,img1,CV_RGB2GRAY);
cvCopy(img, img1);
cvSaveImage("cam_snap.jpg",img1);
cvReleaseImage( &img1 );
cvReleaseImage( &img );
cvReleaseCapture( &capture );
cout << "exit" << endl;
return 0;
}
代碼已成功構建。 我在目標板上運行了.elf可執行文件,並連接了相機(PS3眼),但是生成的圖像看起來像是壞了的電視(像噪音一樣):
在我的主機中,生成的圖像符合預期(鏡頭前的場景)。 您可以就什么地方出了問題或者應該從哪里開始調試方面提出建議?
您應該檢查自己的深度和渠道。 這可能是對齊問題,而且請注意您的圖像可能是BGR而不是RGB。 並且您應該使用cv :: Mat而不是C ++中的IplImage以及VideoCapture而不是CVCapture。
此代碼示例應正常工作。 (未在與您相同的拱門上進行測試)
#include <opencv.hpp>
#include <highgui/highgui.hpp>
#include <imgproc/imgproc.hpp>
#include <iostream>
#include <stdio.h>
using namespace cv;
using namespace std;
int main()
{
VideoCapture capture = cv::VideoCapture(0);
cout << "get here" << endl;
if(!capture.isOpened()) // check if we succeeded
return -1;
cout << "captured" << endl;
Mat img;
capture >> img;
imwrite("./test.png", img);
capture.release();
cout << "exit" << endl;
return 0;
}
希望能有所幫助。
好的,確認。 mini 6410運行USB 1.0,而ps3 eye需要USB 2.0。 我使用標准網絡攝像頭(中文產品,itech pc攝像頭)嘗試了該程序,效果很好。 保存的圖像在攝像機前面顯示場景
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.