7/19/2016

double memcpy to byte, example. useful in serial communication

When we program the serial communication,
You may want to send double number in bytes, rather than strings.

In other words,
when we have 123123123123.123123123123 double value.
it is better send value to byte of sizeof(double), rather than the 25byte string.

The following example further, an example that sends a double 3 dogs as a byte.
...
double x = 1234.4567+10;
  double y = 2345.6789+10;
  double z = 3456.7891+10;

  char sendingStr[sizeof(double) * 3];

  memcpy(sendingStr, &x, sizeof(double));
  memcpy(sendingStr + sizeof(double), &y, sizeof(double));
  memcpy(sendingStr + sizeof(double) * 2, &z, sizeof(double));

  m_Comm.WriteComm((BYTE*)sendingStr, sizeof(double) * 3);
...


In addition, if there is the data to be send prefix is as follows.
...
double x = 1234.4567+10;
  double y = 2345.6789+10;
  double z = 3456.7891+10;

  char sendingStr[sizeof(double) * 3 + 2];
  sendingStr[0] = '_';
  sendingStr[1] = 'E';

  memcpy(sendingStr + 2, &x, sizeof(double));
  memcpy(sendingStr + 2 + sizeof(double), &y, sizeof(double));
  memcpy(sendingStr + 2 + sizeof(double) * 2, &z, sizeof(double));

  m_Comm.WriteComm((BYTE*)sendingStr, sizeof(double) * 3 + 2);
...

And so if you want to change the byte sent back to double is when you do the following:
...
double Mx, My, Mz;
   memcpy(&Mx, MxyzStr, sizeof(double));
   memcpy(&My, MxyzStr+sizeof(double), sizeof(double));
   memcpy(&Mz, MxyzStr + sizeof(double)*2, sizeof(double));
...

Creating a ghost usb boot

firstly, download this files, on here.

This link is my amazon drive. safe.

https://www.amazon.com/clouddrive/share/UsWjAZW1CWCnyIKsqSgzbXhyD10GdkQOTYoQNyNyBNv?ref_=cd_ph_share_link_copy


1)
HPUSBDisk.exe to install the files.
Run the installation file.

Unpack the compressed Bootingimg.zip.
and It sets the path where you extracted.

And click start button.

2)
autoexec.txt, and config.sys file to save your the usb.
(Autoexec.txt file is changed to the autoexec.bat file name.)

3)
After you extract the compressed GHOST.zip, stores with usb.

4)
Now the end if you set the boot order to boot to a usb!

5)
When the boot is called A:> ,  A:> ghost.exe  you can run the ghost.


opencv 3.0 trackbar simple example in video

simple example but good to understand

check..
What is the role of on_trackbar?
But function in Canny g_slider value, why use it?





< git hub - gist >

///

opencv 3.0 trackbar usage simple example

very very simple example
but easy to know the principle




< git-hub gist >

///

7/14/2016

OpenCV Mouse event example code

You can capture mouse event very easy using callback function.
"setMouseCallback” function is that callback function setting.

And many another events, so we can do various of application.
EVENT_MOUSEMOVE      = 0, 
EVENT_LBUTTONDOWN    = 1, 
EVENT_RBUTTONDOWN    = 2, 
EVENT_MBUTTONDOWN    = 3, 
EVENT_LBUTTONUP      = 4, 
EVENT_RBUTTONUP      = 5, 
EVENT_MBUTTONUP      = 6, 
EVENT_LBUTTONDBLCLK  = 7, 
EVENT_RBUTTONDBLCLK  = 8, 
EVENT_MBUTTONDBLCLK  = 9, 
EVENT_MOUSEWHEEL     = 10, 
EVENT_MOUSEHWHEEL    = 11 








< gist start >

< gist end >


#tags
setMouseCallback,

7/13/2016

window program compatibility mode is on. turn it off and then try setup again

To install the language pack for vs 2013, it made things worse.

The error message "window program compatibility mode is on. turn it off and then try setup again."

Simple way to solving, and change the file name to install vssdk_full.exe.









7/07/2016

OpenCV Drawing Example, (line, circle, rectangle, ellipse, polyline, fillConvexPoly, putText, drawContours)

line, circle, rectangle, ellipse, polyline, fillConvexPoly, putText, drawContours example source code!!.















...
//http://study.marearts.com/2016/06/opencv-mat-copyto-clone-roi-example-code.html

#include "opencv2/opencv.hpp"
#include "opencv2/highgui.hpp"
#include <iostream>
#include <vector>

#ifdef _DEBUG               
#pragma comment(lib, "opencv_core331d.lib")       
#pragma comment(lib, "opencv_highgui331d.lib")    
#pragma comment(lib, "opencv_imgcodecs331d.lib")  
#pragma comment(lib, "opencv_objdetect331d.lib")  
#pragma comment(lib, "opencv_imgproc331d.lib")  
#pragma comment(lib, "opencv_videoio331d.lib")    
#else       
#pragma comment(lib, "opencv_core331.lib")       
#pragma comment(lib, "opencv_highgui331.lib")    
#pragma comment(lib, "opencv_imgcodecs331.lib")    
#pragma comment(lib, "opencv_objdetect331.lib")  
#pragma comment(lib, "opencv_imgproc331.lib")  
#pragma comment(lib, "opencv_videoio331.lib")    
#endif        


using namespace std;
using namespace cv;

int main()
{
    Mat img(500, 500, CV_8UC3);
    img.setTo(255);

    
    ///////////////////////////////////////////////////
    //line example
    cv::Point pt(300, 300);
    line(img, Point(10, 10), pt, CV_RGB(255, 0, 0), 2);
    line(img, Point(300, 10), Point(30, 300), Scalar(255, 0, 0), 2);
    ///////////////////////////////////////////////////


    ///////////////////////////////////////////////////
    //Circle example
    circle(img, Point(250, 250), 100, CV_RGB(0, 255, 0), 3);
    cv::Point center(400, 400);
    circle(img, center, 300, Scalar(255, 255, 0), 10);
    circle(img, Point(40, 40), 10, Scalar(255, 0, 0), -1);
    ///////////////////////////////////////////////////


    ///////////////////////////////////////////////////
    //rectangle example
    rectangle(img, Rect(10, 10, 200, 200), CV_RGB(255, 0, 0), 2);
    rectangle(img, Rect(Point(40, 40), Point(400, 400)), Scalar(255, 0, 0), 10);
    ///////////////////////////////////////////////////


    /////////////////////////////////////////////////// 
    //ellipse example 1
    ellipse(img, Point(100, 100), Size(100, 50), 0, 0, 360, CV_RGB(255, 0, 0));
    ellipse(img, Point(100, 100), Size(100, 50), 30, 0, 360, CV_RGB(0, 255, 0));
    ellipse(img, Point(100, 100), Size(100, 50), 60, 0, 360, CV_RGB(0, 0, 255));

    ellipse(img, Point(300, 300), Size(100, 50), 0, 0, 180, CV_RGB(255, 0, 0));
    ellipse(img, Point(300, 300), Size(100, 50), 30, 0, 270, CV_RGB(0, 255, 0));
    ellipse(img, Point(300, 300), Size(100, 50), 60, 0, 360, CV_RGB(0, 0, 255));
    ///////////////////////////////////////////////////

    /////////////////////////////////////////////////// 
    //ellipse example 2
    RotatedRect rRect = RotatedRect(Point2f(300, 300), Size2f(300, 100), 30);
    ellipse(img, rRect, CV_RGB(255, 0, 0));

    //draw rect and inside rect in RotatedRect
    Point2f vertices[4];
    rRect.points(vertices);
    for (int i = 0; i < 4; i++)
        line(img, vertices[i], vertices[(i + 1) % 4], Scalar(0, 255, 0));

    Rect brect = rRect.boundingRect();
    rectangle(img, brect, Scalar(255, 0, 0));
    ///////////////////////////////////////////////////
    

    /*
    ///////////////////////////////////////////////////
    //polylines example 1 
    vector< Point> contour;
    contour.push_back(Point(50, 50));
    contour.push_back(Point(300, 50));
    contour.push_back(Point(350, 200));
    contour.push_back(Point(300, 150));
    contour.push_back(Point(150, 350));
    contour.push_back(Point(100, 100));

    const Point *pts = (const cv::Point*) Mat(contour).data;
    int npts = Mat(contour).rows;

    std::cout << "Number of polygon vertices: " << npts << std::endl;
    // draw the polygon 
    polylines(img, &pts, &npts, 1, false, Scalar(0, 255, 0));

    //polylines example 2 
    contour.clear();
    contour.push_back(Point(400, 400));
    contour.push_back(Point(250, 250));
    contour.push_back(Point(50, 300));

    pts = (const cv::Point*) Mat(contour).data;
    npts = Mat(contour).rows;
    polylines(img, &pts, &npts, 1, true, Scalar(255, 0, 0));
    ///////////////////////////////////////////////////
    */


    /*
    ///////////////////////////////////////////////////
    //fillConvexPoly example 1 
    cv::Point ptss[4];
    ptss[0] = cv::Point(100, 100);
    ptss[1] = cv::Point(150, 200);
    ptss[2] = cv::Point(300, 300);
    ptss[3] = cv::Point(400, 100);

    cv::fillConvexPoly(img, ptss, 4, cv::Scalar(0, 0, 200));
    ///////////////////////////////////////////////////
    */

    /*
    ///////////////////////////////////////////////////
    //textout example 1
    char TestStr[100];
    sprintf_s(TestStr, "total time : %lf sec", 0.001);
    putText(img, TestStr, Point(10, 250), CV_FONT_NORMAL, 1, Scalar(0, 0, 0), 1, 1); //OutImg is Mat class;
    ///////////////////////////////////////////////////
    */

    
    imshow("show0", img);
    waitKey(0);

    return 0;
}
...