Partial differential method of Composite function and multivariate (Chain Rule #1, #2)

Chain Rule #1.



EX) When there are equations,



How to calculate differential about t?














Chain Rule #2









 

EX)





Another example
This example might adapt a problem of the Image optimazation.
 
 

I hope this post help you.
Thank you.

















(TIP) The method to convert 4 bytes array to float

If you have 4 byte array, for example buffer[4], you can change the byte buffer to float.


ex)

union BitConvert{
float f;
unsigned long ul;
};

unsigned char a,b,c,d;
a = buffer[0];
b = buffer[1];
c = buffer[2];
d = buffer[3];

BitConvert EX;
EX.ul = (a << 24)  | (b << 16) | (c << 8) | d;
// or EX.ul = (d << 24) | ( c << 16)  | (b << 8) | a; (It is depend on your plaform.)

There is float value in the "EX.f".

Thank you~. ^^

(TIP) The mean of CR, LF in the serial communication

The mean of the , is like that... in the serial communication.

LF = 10 = 0x0A = '\n'
CR = 13 = 0x0d = '\r'

Thanks you. ^^

How to install OpenGL in Window OS and Visula C++ 2008

You can download OpenCV 3.7 version on this web address http://www.opengl.org/resources/libraries/glut/glut37.zip
The Zip file has below files.



1) You have to copy these file into right directories.


x86  (32bit)
glut32.dll   = C:\Windows\System32
glut.dll       = C:\Windows\System32

x64 (62bit)
glut32.dll   = C:\Windows\sysWOW64
glut.dll       = C:\Windows\sysWOW64

glut.h        = C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include\gl

glut.lib      = C:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib
glut32.lib = C:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib

※  If you met some errors, Copy files additional folder.
C:\Program Files\Microsoft Visual Studio 9.0\VC\lib
C:\Program Files\Microsoft Visual Studio 9.0\VC\include
copy glut.lib, glut32.lib and glut.h into additional folders.

2) Visual Studio Setting
Linker->input, Additional Dependencies -> opengl32.lib glu32.lib glut32.lib

This is example source code.

#include 
void Draw()
{
    glClear(GL_COLOR_BUFFER_BIT);

    glColor3f(1.0f, 0.0f, 1.0f);
    glBegin(GL_QUADS);
        glVertex3f(-0.5f, 0.5f, 0.5f);
        glVertex3f(0.5f, 0.5f, 0.5f);
        glVertex3f(0.5f, -0.5f, 0.5f);
        glVertex3f(-0.5f, -0.5f, 0.1f);
    glEnd();

    glFlush();
}

void main()
{
    glutCreateWindow("NeMo");
    glutDisplayFunc(Draw);
    glutMainLoop();
}

This setting process is normal course, but I met the this errors message in the Visual Studio 2008.
1>NeMo.obj : error LNK2001: __imp____glutCreateWindowWithExit@8 외부 기호를 확인할 수 없습니다.
1>C:\Users\mare\Documents\네이트온 받은 파일\NeMo\Debug\NeMo.exe : fatal error LNK1120: 1개의 확인할 수 없는 외부 참조입니다.

SO, I have solved this problem. I made OpenGL Folder at C:\OpenGL. The Folder has DLL, Lib, Header sub-folders. (DownLoad)
 

I have done directory setting in the Visual Studio options.
And you have to change #include <~> to #include "~" on the source code.

I want to suceess to complie OpneGL Project on your machine.
Thanks you.







(TIP) Matlab Plot Option

colormap
































Below code is example of matlab help document.
x = -pi:pi/10:pi;
y = tan(sin(x)) - sin(tan(x));
plot(x,y,'--rs','LineWidth',2,...
                'MarkerEdgeColor','k',...
                'MarkerFaceColor','g',...
                'MarkerSize',10)



You can describe axes on your image.
data2 = imread('map.tif');
figure(1);
iptsetpref('ImshowAxesVisible','on');
imshow(data2); %'colormap',bone(0)
set(gca, 'XTickLabel', {'a', 'b', 'c', 'd', 'e', 'f'} );
set(gca, 'YTickLabel', {100:100:700} );
xlabel('Longitude');ylabel('Latitude');



(TIP) Making a file name appending number in Matlab

It is simple and easy but I can not remember the code well when I need this code.
So I leave this code in my blog.
And I hope the code is also useful to all visitor.
Thank you.

endIndex = 10;
for j=1:endIndex
     Index = num2str(j);
     dataD = strcat(Index,'saveFile.txt')
     data = load(dataD);
end

->
This source code can load below file names sequentially.
1saveFile.txt
2saveFile.txt
3saveFile.txt
4saveFile.txt
5saveFile.txt
6saveFile.txt
7saveFile.txt
...

Screen capture and save program/ C++ source code


Created Date : 2011.11
Language :C++
Tool : Visual Studio 2008
Library & Utilized : CImage
Reference : Internet
etc. : -



I made this program to help my friend.
This progrma is screen capture program.
At first, we do whole screen capture and set region of screen to capture.
Then start capture and image saving in real-time.
The image file is saved in your program directory.
The file name of the saved image is like that "Time.jpg(EX: 11223242.jpg, 11223243.jpg...)"




The program is made based on below capture program.

#include 
void Capture() 
{ 

   
    int nx =0, ny = 0;
    CImage capImage;
    CWnd *pDesktopWnd = GetDesktopWindow();
    HDC hDC = NULL; 
    if(!pDesktopWnd) 
        return; 
    CWindowDC DeskTopDC(pDesktopWnd); 
    nx = GetSystemMetrics(SM_CXSCREEN);
    ny = GetSystemMetrics(SM_CYSCREEN); 
    if(!capImage.Create(nx, ny, 32))
        return;
    hDC = capImage.GetDC();
    BitBlt(hDC, 0,0, nx, ny, DeskTopDC.m_hDC, 0, 0, SRCCOPY); 
    capImage.Save(_T("test.jpg"), Gdiplus::ImageFormatJPEG); 
    capImage.ReleaseDC();

}


I am hard to make file name of capture image because the progrma requires UNICODE type character.

So I solved this problem as below code.

    int T = time(NULL);
    TCHAR str[100];
    wsprintf(str,_T("%d.jpg"),T);
    ImageTemp.Save(str, Gdiplus::ImageFormatJPEG);     
    ImageTemp.ReleaseDC();

source code


Thread Test in the C++ console mode.

The goal of this source code is how to send large data to the thread and how to wait until all thread finish their job.


I made 3 threads for testing.
I use struct to send the large data.
and I use the flags for waiting the time of the all thread finish.


<source code>


//////////////////////////////////////////////////////////////////////////
// Made by J.H.KIM, 2011 / feelmare@daum.net, feelmare@gmail.com        //
// blog : http://feelmare.blogspot.com                                  //
// My Lab : VISLAB(http://me.pusan.ac.kr)                               //
//////////////////////////////////////////////////////////////////////////

#include <stdio.h>
#include <process.h>
#include <windows.h>

struct InputData
{
    int * data;
    int width;
    int height;
    int OriginW;
    int reserved;
    int flag;
};

void ThreadProcessing(void* pParam);


void main()
{

    //Data Allocation and Setting
    int W = 100;
    int H = 100;
    int * buffer;
    buffer =new int[W*H];
   
    for(int i=0; i<W*H; ++i)
    {
        buffer[i] = i;           
    }
   
    int sx,sy,w,h;

    //thread1, preparing Transite values
    InputData th1_input;   
    sx = 0; sy = 0; w = 80; h = 90; //(80x90) image processing
    th1_input.width = w;
    th1_input.height = h;
    th1_input.OriginW = W;
    th1_input.data = &buffer[sy*W+sx];
    th1_input.reserved = 1;
    th1_input.flag = TRUE;
    _beginthread(ThreadProcessing,0,&th1_input);

    //thread2, preparing Transite values
    InputData th2_input;   
    sx = 10; sy = 10; w = 50; h = 50; //(50x50) image processing
    th2_input.width = w;
    th2_input.height = h;
    th2_input.OriginW = W;
    th2_input.data = &buffer[sy*W+sx];
    th2_input.reserved = 2;
    th2_input.flag = TRUE;
    _beginthread(ThreadProcessing,0,&th2_input);

    //thread3, preparing Transite values
    InputData th3_input;   
    sx = 10; sy = 10; w = 20; h = 20; //(10x10) image processing
    th3_input.width = w;
    th3_input.height = h;
    th3_input.OriginW = W;
    th3_input.data = &buffer[sy*W+sx];
    th3_input.reserved = 3;
    th3_input.flag = TRUE;
    _beginthread(ThreadProcessing,0,&th3_input);


    //wait until all thread is finished.
    while( th1_input.flag || th2_input.flag || th3_input.flag)
    {
        Sleep(100);
    }

    //Data buffer release   
    delete[] buffer;


}


void ThreadProcessing(void* pParam){

    //copy struct data to variable
    int w = ((InputData*)pParam)->width;
    int h = ((InputData*)pParam)->height;
    int ow = ((InputData*)pParam)->OriginW;

    //Processing Sum(v^2.)
    int v;
    double sum=0;
    for(int j=0; j<h; ++j)
    {
        for(int i=0; i<w; ++i)
        {
            v = ((InputData*)pParam)->data[j*ow+i];
            sum += (v*v);
        }       
    }

    printf("%d thread value = %lf\n", ((InputData*)pParam)->reserved , sum);

    ((InputData*)pParam)->flag = FALSE;
}




Please leave comment if the source code has problem.
Thank you~

Web Cam Capture source code using OpenCV

This source code is very simple. But the code will be help to somebody who start to study the opencv.
Thank you~.


    //image class   
    IplImage* image = 0;
    //camera point
    CvCapture* capture = cvCaptureFromCAM(0);
    //make window
    cvNamedWindow( "camera");

    //image class for processing
    IplImage* image2=0;
    //make window
    cvNamedWindow( "camera2");

    unsigned char R,G,B;
    while(1) {
        //capture a frame form cam
        cvGrabFrame( capture );
        //copy to image class
        image = cvRetrieveFrame( capture );

        //create image at one time in the roof
        if(image2 == 0)
        {
            image2  = cvCreateImage(cvSize(image->width, image->height), image->depth, image->nChannels);
        }

        //simple image processing
        for(int i=0; i<image->height; ++i)
        {
            for(int j=0; j<image->width; ++j)
            {
                //to get R,G,B value
                B = (unsigned char)image->imageData[i*image->widthStep+j*3+0];
                G = (unsigned char)image->imageData[i*image->widthStep+j*3+1];
                R = (unsigned char)image->imageData[i*image->widthStep+j*3+2];

                //image color converting
                B = 255-B;
                G = 255-G;
                R = 255-R;

                //copy R,G,B value to image2 
                image2->imageData[i*image2->widthStep+j*3+0] = B;
                image2->imageData[i*image2->widthStep+j*3+1] = G;
                image2->imageData[i*image2->widthStep+j*3+2] = R;
            }
        }

        //show window
        cvShowImage( "camera", image );
        cvShowImage( "camera2", image2 );

        //break
        if( cvWaitKey(10) >= 0 )
            break;
    }

    //release imge
    cvReleaseImage(&image2);
    //release capture point
    cvReleaseCapture( &capture );
    //close the window
    cvDestroyWindow( "camera" );
    cvDestroyWindow( "camera2" );