Felipe Aplaplac
Felipe Aplaplac

Reputation: 29

migrating code from Microsoft Visual C++ to debian (raspberry)

My English is not very good (im from Chile) but will try to explain in the best way possible (+ google translator :P)

well im working in Microsoft Visual C++ 2010 express and I need to migrate my opencv code to Linux to work on a rapsberry

Here the code:

#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;
}

copying and pasting the code into a file "codigo.c" and compiling (in linux terminal) with

gcc codigo.c -o codigo $(pkg-config --cflags --libs opencv)

I have the following error

codigo.c:3:21 fatal error: StdAfx.h: No such file or directory
compilation terminated.

well, google told me that StdAfx.h is a header of microsoft visual c++

and here i crash :l

i dont know what can i do now

I hope someone can tell me some way to go to fix this problem

thx to all

Upvotes: 2

Views: 479

Answers (1)

dsu
dsu

Reputation: 81

As your code does not depend on anything other than opencv, you can just leave out the stdafx header. it's a feature of visual studio that you dont need here.

( see Purpose of stdafx.h )

it compiles fine on my machine. with:

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv/cv.h>

note the "/". please use these instead of backslashes here, or unix machines will complain.

also: use g++ to compile this code, not gcc.

Upvotes: 3

Related Questions