我的英语不是很好(我来自智利)但会尽量以最好的方式解释(+谷歌翻译:P)
我在 Microsoft Visual C++ 2010 express 中工作,我需要将我的 opencv 代码迁移到 Linux 以在 rapsberry 上工作
这里的代码:
#include "StdAfx.h"
#include <opencv2\core\core.hpp>
#include <opencv2\highgui\highgui.hpp>
#include <opencv\cv.h>
//#include <iostream>
using namespace cv;
int main( int argc, char** argv )
{
//Variable
CvCapture* capture = 0;
IplImage* frame = 0;
IplImage* frame_black = 0;
IplImage* frame_blue = 0;
IplImage* frame_red = 0;
//IplImage* red_gray = 0;
//Verifica Camara
capture = cvCaptureFromCAM(1);
if( !cvGrabFrame( capture )){
printf("error cámara");
exit(0);
}
//Comienza
for(;;){
// Captura imagen from camara
frame = cvQueryFrame(capture);
if( !frame ) break;
// filtro negro
frame_black = cvCreateImage(cvGetSize(frame),8,3);
CvScalar r,g;
for(int i=0;i<(frame->height);i++){
for(int j=0;j<(frame->width);j++){
r=cvGet2D(frame,i,j);
if((r.val[2]<80)&&(r.val[1]<80)&&(r.val[0]<80)){
g.val[2]=0;
g.val[1]=0;
g.val[0]=0;
cvSet2D(frame_black,i,j,g);
}
else{
g.val[2]=255;
g.val[1]=255;
g.val[0]=255;
cvSet2D(frame_black,i,j,g);
}
}
}
// filtro azul
frame_blue = cvCreateImage(cvGetSize(frame),8,3);
CvScalar s,c;
for(int i=0;i<(frame->height);i++){
for(int j=0;j<(frame->width);j++){
s=cvGet2D(frame,i,j);
if((s.val[2]<100)&&(s.val[1]<100)&&(s.val[0]>100)){
c.val[2]=0;
c.val[1]=0;
c.val[0]=255;
cvSet2D(frame_blue,i,j,c);
}
else{
c.val[2]=255;
c.val[1]=255;
c.val[0]=255;
cvSet2D(frame_blue,i,j,c);
}
}
}
// filtro rojo
frame_red = cvCreateImage(cvGetSize(frame),8,3);
CvScalar p,q;
for(int i=0;i<(frame->height);i++){
for(int j=0;j<(frame->width);j++){
p=cvGet2D(frame,i,j);
if((p.val[2]>100)&&(p.val[1]<100)&&(p.val[0]<100)){
q.val[2]=255;
q.val[1]=0;
q.val[0]=0;
cvSet2D(frame_red,i,j,q);
}
else{
q.val[2]=255;
q.val[1]=255;
q.val[0]=255;
cvSet2D(frame_red,i,j,q);
}
}
}
/* filtro hough
red_gray = cvCreateImage(cvGetSize(frame),8,1);
cvCvtColor( frame_red, red_gray, CV_BGR2GRAY);
cvSmooth(red_gray, red_gray, CV_BLUR,3);
CvMemStorage* storage_var = cvCreateMemStorage(0);
CvSeq* results = cvHoughCircles(red_gray, storage_var , CV_HOUGH_GRADIENT , 2, red_gray->height/3 );
// reemplaza
for( int i = 0; i < results->total; i++ ){
float* p = (float*) cvGetSeqElem( results, i );
CvPoint pt = cvPoint( cvRound( p[0] ), cvRound( p[1] ));
cvCircle(red_gray,pt,cvRound( p[2] ),cvScalar(0,0,255),1.8);
}
*/
// mostrar en ventana
cvShowImage("ventana",frame_black);
if( cvWaitKey( 10 ) >= 0 )
break;
}
//Libera de memoria
cvReleaseCapture( &capture);
cvReleaseImage( &frame);
cvReleaseImage( &frame_black);
cvReleaseImage( &frame_blue);
cvReleaseImage( &frame_red);
//cvReleaseImage( &red_gray);
return 0;
}
将代码复制并粘贴到文件“codigo.c”中并编译(在linux终端中)
gcc codigo.c -o codigo $(pkg-config --cflags --libs opencv)
我有以下错误
codigo.c:3:21 fatal error: StdAfx.h: No such file or directory
compilation terminated.
好吧,谷歌告诉我 StdAfx.h 是 microsoft visual c++ 的标头
我在这里崩溃了:l
我不知道我现在能做什么
我希望有人能告诉我一些解决这个问题的方法
谢谢大家