我遇到麻烦,如果理解某些编码我很抱歉,如果这是愚蠢但但我有一个代码从我的网络摄像头捕获视频我想从帧中获得RGB值,如果这是不可能的将不得不将帧保存为图片,然后从中获取值?
const char window_name [] =“网络摄像头”;
int main(int argc,char * argv []) {
/* attempt to capture from any connected device */
CvCapture *capture=cvCaptureFromCAM(CV_CAP_ANY);
if(!capture)
{
printf("Failed to initialise webcam\n");
return -1;
}
/* create the output window */
cvNamedWindow(window_name, CV_WINDOW_NORMAL);
do
{
/* attempt to grab a frame */
IplImage *frame=cvQueryFrame(capture);
if(!frame)
{
printf("Failed to get frame\n");
break;
}
COLORREF myColAbsolute = GetPixel(frame, 10,10);//error in saying frame is not compatible with HDC.
cout << "Red - " << (int)GetRValue(myColAbsolute) << endl;
cout << "Green - " << (int)GetGValue(myColAbsolute) << endl;
cout << "Blue - " << (int)GetBValue(myColAbsolute) << endl;
/* show the frame */
cvShowImage(window_name, frame);
答案 0 :(得分:1)
GetPixel()是一个Windows函数,而不是一个opencv函数。同样适用于GetRValue()和姐妹。
你在原生的win32 api中使用它们来从HDC获取一个像素,但它不适用于opencv / highgui,因为HDC和HWND都没有暴露。
因为你显然是一个初学者(再没有错!)让我试着用你原来的1.0 opencv api(IplImages,cv * Functions)来讨论你, 你应该使用新的(cv :: Mat,namespace cv :: Functions)。
#include "opencv2/opencv.hpp"
#include "opencv2/highgui/highgui.hpp"
using namespace cv;
using namespace std;
int main()
{
Mat frame;
namedWindow("video", 1);
VideoCapture cap(0);
while ( cap.isOpened() )
{
cap >> frame;
if(frame.empty()) break;
int x=3, y=5;
// Ladies and Gentlemen, the PIXEL!
Vec3b pixel = frame.at<Vec3b>(y,x); // row,col, not x,y!
cerr << "b:" << int(pixel[0]) << " g:" << int(pixel[1]) << " r:" << int(pixel[2]) << endl;
imshow("video", frame);
if(waitKey(30) >= 0) break;
}
return 0;
}