0
votes

I am currently trying to process an image and detect a circle, and send some protocol to the land base thru zigbee. I researched this and tried what I found, but none of them work.

The following is the code that I tried:

    #ifdef __BORLANDC__
#pragma hdrstop            // borland specific
#include <condefs.h>       
#pragma argsused           
USEUNIT("Tserial.cpp");    
#endif

#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <c:\OpenCV243\include\opencv\cv.h>
#include <c:\OpenCV243\include\opencv\highgui.h>
#include <math.h>
#include "Tserial.h"
#include <iostream>

using namespace std;
using namespace cv;

  int zigbee_command;
  Tserial *zigbee_com;
  unsigned char protocol = 0;

int main( int argc, char **argv )
{
    CvCapture *capture = 0;
    IplImage  *img = 0;
    int       key = 0;
    int px;
int py;
    CvFont font;
    cvInitFont(&font, CV_FONT_HERSHEY_PLAIN,1.0,1.0,0,1,CV_AA);

    #pragma region find_camera
 
    capture = cvCaptureFromCAM( 0 );
        #pragma endregion

    #pragma region detect_image
    if ( !capture ) {
        fprintf( stderr, "Cannot open initialize webcam!\n" );
        return 1;
    }
    #pragma endregion
 
    cvNamedWindow( "result", CV_WINDOW_AUTOSIZE );

#pragma region serial
     // // serial to zigbee setup 
  zigbee_com = new Tserial();
  if (zigbee_com!=0) {
       zigbee_com->connect("COM5", 9600, spNONE); } 
  //// serial to zigbee setup 
#pragma endregion 
    img = cvQueryFrame( capture );
    if (!img)
        exit(1);
    IplImage* gray = cvCreateImage( cvGetSize(img), 8, 1 );
    CvMemStorage* storage = cvCreateMemStorage(0);
 
    while( key != 'q' ) {
        img = cvQueryFrame( capture );
        if( !img ) break; 
 
 
        cvCvtColor( img, gray, CV_BGR2GRAY );
        cvSmooth( gray, gray, CV_GAUSSIAN, 9, 9 );
        CvSeq* circles = cvHoughCircles( gray, storage, CV_HOUGH_GRADIENT, 2, gray->height/4, 200, 100, 20, 100 );
        int i;
        for( i = 0; i < circles->total; i++ )
        {
            float* p = (float*)cvGetSeqElem( circles, i );
        
            cvCircle( img, cvPoint(cvRound(p[0]),cvRound(p[1])), cvRound(p[2]), CV_RGB(0,0,255), 2, 8, 0 );
            cvLine (img, cvPoint(cvRound(p[0]+40),cvRound(p[1])), cvPoint(cvRound(p[0]),cvRound(p[1])), CV_RGB(0,255,0), 1, CV_AA,0);
            cvLine (img, cvPoint(cvRound(p[0]),cvRound(p[1]+40)), cvPoint(cvRound(p[0]),cvRound(p[1])), CV_RGB(0,255,0), 1, CV_AA,0);
            cvLine (img, cvPoint(cvRound(p[0]-40),cvRound(p[1])), cvPoint(cvRound(p[0]),cvRound(p[1])), CV_RGB(0,255,0), 1, CV_AA,0);
            cvLine (img, cvPoint(cvRound(p[0]),cvRound(p[1]-40)), cvPoint(cvRound(p[0]),cvRound(p[1])), CV_RGB(0,255,0), 1, CV_AA,0);
       
            px=cvRound(p[0]); 
py=cvRound(p[1]);
if((px < 330 && px > 320) && (py > 230 && py < 250))
{
    
     cvPutText(img, "CENTER",cvPoint(cvRound(p[0]+45),cvRound(p[1]+45)), &font, CV_RGB(0,0,255));

     protocol = 'okie'; 
     zigbee_com->sendChar(protocol);

}
 // displays coordinates of circle's center
cout <<"(x,y) -> ("<<px<<","<<py<<")"<<endl;
        }
 
        cvShowImage( "result", img );
        key = cvWaitKey( 1 );
 
    }
 
    cvDestroyWindow( "result" );
    cvReleaseCapture( &capture );   
 
    return 0;
}

The serial source is from: http://www.tetraedre.com/advanced/serial/

Errors:

1>DetectCircle.obj : error LNK2019: unresolved external symbol "public: void __cdecl Tserial::sendChar(char)" (?sendChar@Tserial@@QEAAXD@Z) referenced in function main

1>DetectCircle.obj : error LNK2019: unresolved external symbol "public: int __cdecl Tserial::connect(char *,int,enum serial_parity)" (?connect@Tserial@@QEAAHPEADHW4serial_parity@@@Z) referenced in function main

1>DetectCircle.obj : error LNK2019: unresolved external symbol "public: __cdecl Tserial::Tserial(void)" (??0Tserial@@QEAA@XZ) referenced in function main 1>C:\Users\Steven\Documents\Visual Studio 2010\Projects\mynewproject\x64\Debug\mynewproject.exe : fatal error LNK1120: 3 unresolved externals

1
If you could elaborate on "i did research and tried the ways", you might get better help. - WildCrustacean
i tried using Tserial.h, which i downloaded, the code is something like int zigbee_command; Tserial *zigbee_com; unsigned char protocol = 0; //in the condition part for sending i have protocol = 'ok'; zigbee_com->sendChar( protocol); tetraedre.com/advanced/serial/tserial.h - Steven
i have added the code in - Steven
Do you have Tserial.cpp that implements the class as part of the project? That looks like the problem to me. - PeterJ
hmmm sorry i dont get you, i am at novice level. i have place the Tserial.cpp in the project folder. have you solved the problem ? - Steven

1 Answers

3
votes

Those are linker errors because while Tserial.cpp that implements the class has been copied to the same directory the compiler doesn't know about them. You need go to project | add existing item and add it there so it knows it's part of the project and builds and links it.

Additionally you have the following code that attempts to store a string into a single character and send it which won't work:

unsigned char protocol = 0;
protocol = 'okie'; 
zigbee_com->sendChar(protocol);

Based on the example from sertest2.cpp included along with that class you can use the following to send a string, where 4 is the length of the data to be sent:

zigbee_com->sendArray("okie", 4);