Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to send value with serial port (C Language)

Hello guys,

I am doing a project where I get the pixel value from a binary image (black and white - 0 and 255). Now I need to get this pixel value and send it with serial port, where a xBee is connected, but I don't know how can I do that.

I would appreciate it if someone could help me to send the pixel value to the xBee with serial port.

My code to get the pixel value from a binary image is:

#include <opencv\cv.h>
#include <opencv\highgui.h>
#include <stdio.h>
#include <stdlib.h>

int main()
{
    uchar binario, valor;

    FILE *fp;
    fp = fopen("Pixel.txt", "w");

    if(fp == NULL){
        printf("\nNão encontrei arquivo\n");
        exit(EXIT_FAILURE);
    }

    cvNamedWindow( "original", CV_WINDOW_AUTOSIZE );
    cvNamedWindow( "new", CV_WINDOW_AUTOSIZE );

    IplImage* src = cvLoadImage("Koala.jpg", CV_LOAD_IMAGE_GRAYSCALE);
    cvShowImage("original", src);

    CvSize size = cvSize(100, 100); 
    IplImage* resize = cvCreateImage(size, src->depth, src->nChannels); 

    cvResize(src, resize, CV_INTER_LINEAR);

    IplImage* img_binario = cvCreateImage(cvGetSize(resize), IPL_DEPTH_8U, 1);
    cvThreshold(resize, img_binario, 100, 255, CV_THRESH_BINARY);

    for(int i = 0; i < img_binario->height; i++){
        for(int j = 0; j < img_binario->width; j++){
            binario = ((uchar *)(img_binario->imageData + i*img_binario->widthStep))[j];

            if(binario == 255)
                valor = 1;
            else
                valor = 0;
            fprintf(fp, "Valor = %i\n", valor);
        }
    }

    fclose(fp);

    cvShowImage("new", img_binario);

    cvWaitKey(0);
    return 0;
}

Thank you.

How to send value with serial port (C Language)

Hello guys,

I am doing a project where I get the pixel value from a binary image (black and white - 0 and 255). Now I need to get this pixel value and send it with serial port, where a xBee is connected, but I don't know how can I do that.

I would appreciate it if someone could help me to send the pixel value to the xBee with serial port.

My code to get the pixel value from a binary image is:

#include <opencv\cv.h>
#include <opencv\highgui.h>
#include <stdio.h>
#include <stdlib.h>

int main()
{
    uchar binario, valor;

    FILE *fp;
    fp = fopen("Pixel.txt", "w");

    if(fp == NULL){
        printf("\nNão encontrei arquivo\n");
        exit(EXIT_FAILURE);
    }

    cvNamedWindow( "original", CV_WINDOW_AUTOSIZE );
    cvNamedWindow( "new", CV_WINDOW_AUTOSIZE );

    IplImage* src = cvLoadImage("Koala.jpg", CV_LOAD_IMAGE_GRAYSCALE);
    cvShowImage("original", src);

    CvSize size = cvSize(100, 100); 
    IplImage* resize = cvCreateImage(size, src->depth, src->nChannels); 

    cvResize(src, resize, CV_INTER_LINEAR);

    IplImage* img_binario = cvCreateImage(cvGetSize(resize), IPL_DEPTH_8U, 1);
    cvThreshold(resize, img_binario, 100, 255, CV_THRESH_BINARY);

    for(int i = 0; i < img_binario->height; i++){
        for(int j = 0; j < img_binario->width; j++){
            binario = ((uchar *)(img_binario->imageData + i*img_binario->widthStep))[j];

            if(binario == 255)
                valor = 1;
            else
                valor = 0;
            fprintf(fp, "Valor = %i\n", valor);
        }
    }

    fclose(fp);

    cvShowImage("new", img_binario);

    cvWaitKey(0);
    return 0;
}

Thank you.