Tuesday, March 29, 2011

certified translator

http://www.atia.ab.ca/

Certifications:
Translator: ZH-EN
  • Lixia (Lisa) Zhang
    email | Tel: 775-5028
  • Claudia Mejia 
           1200,910-7ave sw
           265.1120

    Saturday, March 26, 2011

    WE.Pepsi.Infi vs WeMadeFOX_Moon 3set 3of6 [ENG]

    http://www.youtube.com/watch?v=7O2Zkcr1EEQ&NR=1


    kalman filter opcv

    #include "stdafx.h"
    #include <cv.h>
    #include <highgui.h>
    #include <cxcore.h>
    #include <math.h>
    #include <ctype.h>
    #include <stdio.h>
    int _tmain(int argc, _TCHAR* argv[])
    {
     // Initialize Kalman filter object, window, number generator, etc
     cvNamedWindow( "Kalman", 1 );
     CvRandState rng;
     cvRandInit( &rng, 0, 1, -1, CV_RAND_UNI );
     IplImage* img = cvCreateImage( cvSize(500,500), 8, 3 );
     CvKalman* kalman = cvCreateKalman( 2, 1, 0 );
     // State is phi, delta_phi - angle and angular velocity
     // Initialize with random guess
     CvMat* x_k = cvCreateMat( 2, 1, CV_32FC1 );
     cvRandSetRange( &rng, 0, 0.1, 0 );
     rng.disttype = CV_RAND_NORMAL;
     cvRand( &rng, x_k );
     // Process noise
     CvMat* w_k = cvCreateMat( 2, 1, CV_32FC1 );
     // Measurements, only one parameter for angle
     CvMat* z_k = cvCreateMat( 1, 1, CV_32FC1 );
     cvZero( z_k );
     // Transition matrix F describes model parameters at and k and k+1
     const float F[] = { 1, 1, 0, 1 };
     memcpy( kalman->transition_matrix->data.fl, F, sizeof(F));
     // Initialize other Kalman parameters
     cvSetIdentity( kalman->measurement_matrix, cvRealScalar(1) );
     cvSetIdentity( kalman->process_noise_cov, cvRealScalar(1e-5) );
     cvSetIdentity( kalman->measurement_noise_cov, cvRealScalar(1e-1) );
     cvSetIdentity( kalman->error_cov_post, cvRealScalar(1) );
     // Choose random initial state
     cvRand( &rng, kalman->state_post );
     // Make colors
     CvScalar yellow = CV_RGB(255,255,0);
     CvScalar white = CV_RGB(255,255,255);
     CvScalar red = CV_RGB(255,0,0);
     while( 1 ){
      // Predict point position
      const CvMat* y_k = cvKalmanPredict( kalman, 0 );
      // Generate Measurement (z_k)
      cvRandSetRange( &rng, 0, sqrt( kalman->measurement_noise_cov->data.fl[0] ), 0 );  
      cvRand( &rng, z_k );
      cvMatMulAdd( kalman->measurement_matrix, x_k, z_k, z_k );
     
      // Plot Points
      cvZero( img );
      // Yellow is observed state
      cvCircle( img,
       cvPoint( cvRound(img->width/2 + img->width/3*cos(z_k->data.fl[0])),
       cvRound( img->height/2 - img->width/3*sin(z_k->data.fl[0])) ),
       4, yellow );
      // White is the predicted state via the filter
      cvCircle( img,
       cvPoint( cvRound(img->width/2 + img->width/3*cos(y_k->data.fl[0])),
       cvRound( img->height/2 - img->width/3*sin(y_k->data.fl[0])) ),
       4, white, 2 );
      // Red is the real state
      cvCircle( img,
       cvPoint( cvRound(img->width/2 + img->width/3*cos(x_k->data.fl[0])),
       cvRound( img->height/2 - img->width/3*sin(x_k->data.fl[0])) ),
       4, red );
      cvShowImage( "Kalman", img );
      // Adjust Kalman filter state
      cvKalmanCorrect( kalman, z_k );
      // Apply the transition matrix F and apply "process noise" w_k
      cvRandSetRange( &rng, 0, sqrt( kalman->process_noise_cov->data.fl[0] ), 0 );
      cvRand( &rng, w_k );
      cvMatMulAdd( kalman->transition_matrix, x_k, w_k, x_k );
      // Exit on esc key
      if( cvWaitKey( 100 ) == 27 )
       break;
     }
     return 0;
    }
    -----------------------------------------------------------------------

    Friday, March 25, 2011

    Thursday, March 24, 2011

    opcv Lucas-Kanade optical flow





    ----------------------------------------------------------------------------
    #include "stdafx.h"
    #include <cv.h>
    #include <highgui.h>
    #include <cxcore.h>
    #include <math.h>
    #include <ctype.h>
    #include <stdio.h>
    IplImage *eig_image = NULL, *temp_image = NULL;
    const double pi = 3.14159265358979323846;
    double square(int a)
    {
    return a * a;
    }
    int main(void)
    {
    IplImage* input_video = cvLoadImage( "C:\\Users\\abc\\Desktop\\IMG_0039.jpg" );
    CvSize frame_size;
    frame_size.height = input_video->height;
    frame_size.width = input_video->width;
    IplImage* frame1 = cvCreateImage(frame_size, IPL_DEPTH_8U, 1 );
    cvConvertImage(input_video, frame1, CV_CVTIMG_FLIP);
    CvPoint2D32f frame1_features[400];
    CvPoint2D32f frame2_features[400];
    int number_of_features=400;
    cvGoodFeaturesToTrack(frame1, eig_image, temp_image, frame1_features, &number_of_features, .01, .01, NULL);
    char optical_flow_found_feature[400];
    float optical_flow_feature_error[400];
    CvTermCriteria optical_flow_termination_criteria = cvTermCriteria( CV_TERMCRIT_ITER | CV_TERMCRIT_EPS, 20, 0.3 );
    IplImage* input_video1  = cvLoadImage( "C:\\Users\\abc\\Desktop\\IMG_0040.jpg" );
    IplImage* frame2 = cvCreateImage(frame_size, IPL_DEPTH_8U, 1 );
    cvConvertImage(input_video1, frame2, CV_CVTIMG_FLIP);
    IplImage *pyramid1 = cvCreateImage( frame_size, IPL_DEPTH_8U, 1 );
    IplImage *pyramid2 = cvCreateImage( frame_size, IPL_DEPTH_8U, 1 );
    CvSize optical_flow_window = cvSize(3,3);
    cvCalcOpticalFlowPyrLK(frame1, frame2, pyramid1, pyramid2, frame1_features,
            frame2_features, number_of_features, optical_flow_window, 5,
            optical_flow_found_feature, optical_flow_feature_error,
            optical_flow_termination_criteria, 0 );
    for(int i = 0; i < number_of_features; i++)
    {
     if ( optical_flow_found_feature[i] == 0 ) continue;
     int line_thickness = 10;
     CvScalar line_color = CV_RGB(255,0,0);
    CvPoint p,q;
    p.x = (int) frame1_features[i].x;
    p.y = (int) frame1_features[i].y;
    q.x = (int) frame2_features[i].x;
    q.y = (int) frame2_features[i].y;
    double angle = atan2( (double) p.y - q.y, (double) p.x - q.x );
    double hypotenuse = sqrt( square(p.y - q.y) + square(p.x - q.x) );
    q.x = (int) (p.x - 3 * hypotenuse * cos(angle));
    q.y = (int) (p.y - 3 * hypotenuse * sin(angle));
    cvLine( frame1, p, q, line_color, line_thickness, CV_AA, 0 );
    p.x = (int) (q.x + 9 * cos(angle + pi / 4));
    p.y = (int) (q.y + 9 * sin(angle + pi / 4));
    cvLine( frame1, p, q, line_color, line_thickness, CV_AA, 0 );
    p.x = (int) (q.x + 9 * cos(angle - pi / 4));
    p.y = (int) (q.y + 9 * sin(angle - pi / 4));
    cvLine( frame1, p, q, line_color, line_thickness, CV_AA, 0 );
    }
    cvNamedWindow( "Optical Flow", 0 );
    cvShowImage("Optical Flow", frame1);
    int p[3]; p[0] = CV_IMWRITE_JPEG_QUALITY; p[1] = 100; p[2] = 0; cvSaveImage("out2.jpg", frame1, p);
    cvNamedWindow( "Optical Flow1", 0 );
    cvShowImage("Optical Flow1", frame2);
    cvWaitKey(0);
    }
    ------------------------------------------------------------------------------

    cvCalcOpticalFlowFarneback

    #include "stdafx.h"
    #include <cv.h>
    #include <highgui.h>
    #include <cxcore.h>
    #include <math.h>
    #include <ctype.h>
    #include <stdio.h>
    IplImage *image = 0, *grey = 0, *prev_grey = 0, *pyramid = 0, *prev_pyramid = 0, *swap_temp;
    int win_size = 10;
    const int MAX_COUNT = 500;
    CvPoint2D32f* points[2] = {0,0}, *swap_points;
    char* status = 0;
    int count = 0;
    int need_to_init = 0;
    int night_mode = 0;
    int flags = 0;
    int add_remove_pt = 0;
    CvPoint pt;
    int main()
    {
     int scale = 5;
        cvNamedWindow("vel", 1);
        cvNamedWindow("image1", 1);
        cvNamedWindow("image2", 1);
     CvSize isize = cvSize(80,80);
     CvSize vsize = cvSize(isize.width * scale, isize.height * scale);
     IplImage *image1 = cvCreateImage(isize, 8, 1 );
     IplImage *image2 = cvCreateImage(isize, 8, 1 );
     IplImage *velx = cvCreateImage(isize, IPL_DEPTH_32F, 1);
     IplImage *vely = cvCreateImage(isize, IPL_DEPTH_32F, 1);
     IplImage *vel = cvCreateImage(vsize, 8, 3);
        IplImage *flow = cvCreateImage(isize, IPL_DEPTH_32F, 2);
     int sim = 0;
        for (;;)
        {
      if (sim * 4 > isize.width*3 /4)
       sim = 0;
      CvPoint pts1 = {sim * 1, 30};
      CvPoint pts2 = {pts1.x + 4, pts1.y + 4};
      cvZero(image1);
      cvRectangle(image1, pts1, pts2, CV_RGB(255, 255, 255), -1);
      pts1.x += 1;
      pts2.x += 1;
      cvZero(image2);
      cvRectangle(image2, pts1, pts2, CV_RGB(255, 255, 255), -1);
      sim++;
    #if 0
      cvCalcOpticalFlowLK(image1, image2, cvSize(5,5), velx, vely);
    #else
    #if 1
            cv::Mat im1 = cv::cvarrToMat(image1), im2 = cv::cvarrToMat(image2);
            cv::Mat _flow = cv::cvarrToMat(flow);
            cv::calcOpticalFlowFarneback( im1, im2, _flow, 0.5, 2, 5, 2, 7, 1.5, cv::OPTFLOW_FARNEBACK_GAUSSIAN);
    #else
            //cvCalcOpticalFlowFarneback(image1, image2, flow, 0.5, 1, 5, 2, 7, 1.5, 0);
            icvCalcOpticalFlowBBW( im1, im2, _flow, 1, 1, 1, 0 );
    #endif
            {
                for( int y = 0; y < flow->height; y++ )
                {
                    float* vx = (float*)(velx->imageData + velx->widthStep*y);
                    float* vy = (float*)(vely->imageData + vely->widthStep*y);
                    const float* f = (const float*)(flow->imageData + flow->widthStep*y);
                    for( int x = 0; x < flow->width; x++ )
                    {
                        vx[x] = f[2*x];
                        vy[x] = f[2*x+1];
                    }
                }
            }
    #endif
      CvPoint2D64f ave = {0,0};
      cvZero(vel);
      pts1.x *= scale;
      pts1.y *= scale;
      pts2.x *= scale;
      pts2.y *= scale;
      cvRectangle(vel, pts1, pts2, CV_RGB(255, 255, 255), 1);
      for (int y = 0; y < image1->height; y++)
       for (int x = 0; x < image1->width; x++)
       {
        double dx = cvGetReal2D(velx, y, x);
        double dy = cvGetReal2D(vely, y, x);
        CvPoint p = cvPoint(x * scale, y * scale);
        cvLine(vel, p, p, cvScalar(170,170,170));
        ave.x += dx;
        ave.y += dy;
        double l = sqrt(dx*dx + dy*dy);
        if (l > 0)
        {
         CvPoint p2 = cvPoint(p.x + (int)(dx * 10 + .5), p.y + (int)(dy * 10 + .5));
         cvLine(vel, p, p2, CV_RGB(0,255,0), 1, 8);
        }
       }
      cvShowImage("vel", vel);
      cvShowImage("image1", image1);
      cvShowImage("image2", image2);
      printf("ave=(%.2f,%.2f)\n", ave.x, ave.y);
            if( cvWaitKey(300) == 'q' )
                break;
        }
        return 0;
    }