2016년 11월 23일 수요일

[C# LnaguageExt] Curry and fun Example

using lx = LanguageExt;
using  static LanguageExt.Prelude;

namespace ConsoleApplication2
{
    class Program
    {

        static void Main( string[] args )
        {
            Func temp = (a,b,c,d) =>
            {
                return a+b+c+d;
            };

            var add12 = curry( temp )( 1 )( 2 ); // using  static LanguageExt.Prelude; 으로 curry 바로 접근
            Console.WriteLine( add12( 5 )(5) );
           
            var temp4 = fun( (int x,int y) => Console.WriteLine(3) ); // using  static LanguageExt.Prelude; 으로 fun바로 접근
            var temp4_1 = curry(temp4)(3); // lx.Unit 은 위의 temp4 의 리턴타입
            var temp5 = (Action)(()=>Console.Write(3));
            Console.ReadLine();
        }
    }

2016년 11월 22일 화요일

[opencv python] cv2.imread cv2.imshow

def get_im_cv2(path):
    img = cv2.imread(path,1)
    resized = cv2.resize(img, (32, 32), cv2.INTER_LINEAR)
    #cv2.startWindowThread("preview")
    cv2.imshow("preview", resized)
    key = cv2.waitKey(0)
    if key == ord('t'):
        cv2.destroyWindow("preview")
 
    return resized


or


def get_im_cv2(path):
    img = cv2.imread(path,1)
    resized = cv2.resize(img, (32, 32), cv2.INTER_LINEAR)
    #cv2.startWindowThread("preview")
    cv2.imshow("preview", resized)
    cv2.waitKey(0)
 
    return resized


waitKey 는 반드시 써줘야 이미지가 나온다.

[c#] File Stream Example

File Stream


-------------------
static void Main( string[] args )
        {

            Console.WriteLine( "hellow" );
            Stream s = new FileStream( "test.txt" , FileMode.Create );

            Console.WriteLine( s.CanRead );
            Console.WriteLine( s.CanWrite );
            Console.WriteLine( s.CanSeek );

            int temp = 6;
            byte[] temp2 = BitConverter.GetBytes(temp);

            Console.WriteLine( "temp2 length  :" + temp2.Length.ToString() );

            s.Write( temp2 , 0 , temp2.Length );
            s.WriteByte( 102 );
            byte[] block = { 1,2,3,4,5,};
            s.Write( block , 0 , block.Length );

            Console.WriteLine( s.Length );
            Console.WriteLine( s.Position );
            s.Position = 0;

            Console.WriteLine( "ReadByte1 : " + s.ReadByte() );
            Console.WriteLine( "ReadByte2 : " + s.ReadByte() );

            Console.WriteLine( s.Read( block , 0 , block.Length ) );
            s.Close();
            Console.ReadLine();
        }

-----------------

[opencv] Filter

Median : cv2.medianBlur(originimg,5) -> 2번쨰는 필터 크기

Biliteral : cv2.bilateralFilter(originimg,5(d),sigma color,sigma Space)

d -> 필터크기. 보통5정도 사용. -1 시 sigma space에의해 자동으로 계산됨
sigma color -> 컬러공간에서 필터표준편차  값이 크면 멀리 떨어진 색상을 혼합하여 유사한 색상으로 뭉개서 큰영역으로 만든다.
sigma space -> 좌표공간에서 필터 표준편차이다. 값이 크면 sigma color 에 의해 색상이 충분히 가까우면서 위치가 멀리 떨어진 이웃화소가 영향을 준다

2016년 11월 21일 월요일

[opencv] threshold

ret,thresh2 = cv2.threshold(img,50,255,cv2.THRESH_BINARY_INV)

threshold (소스 , 임계치, 최대값(Max), 출력 종륲 (dst라고한다.))

- dst 는

Binary = 임계치보다 크면 Max치 / 작으면 0
Trunc= 임계치보다 크면 Max치 / 작으면 소스
Tozero= 임계치보다 크면 소스  / 작으면 0



---------------------------------------
meanthimg = cv2.adaptiveThreshold(img,255,cv2.ADAPTIVE_THRESH_MEAN_C,\
    cv2.THRESH_BINARY,17, 0)


마지막 인수는 parameter1 인데 이것은 blovksize 17에서 구한 임계치 - paramete1 으로 임계치가 결정된다.

2016년 11월 15일 화요일

[C#] Closure Example

class Program
    {
        static void Main( string[] args )
        {
            myFunc(1)(2)(3);
            var partial = myFunc(4)(4);
            var sum1 = partial(1);
            var sum2 = partial(2);
            var sum3 = partial(3);
            var sum4 = partial(4);
        }

        static Func& myFunc( int x ) => ( y ) => ( z ) => x + y + z;
    }

[C#] Closure Example

class Program
    {
        static void Main( string[] args )
        {
            myFunc(1)(2)(3);
            var partial = myFunc(4)(4);
            var sum1 = partial(1);
            var sum2 = partial(2);
            var sum3 = partial(3);
            var sum4 = partial(4);
        }

        static Func> myFunc( int x ) => ( y ) => ( z ) => x + y + z;
    }

2016년 11월 9일 수요일

[C#] Currying

method ( par1, par2, par3) => return result



Currymethod(par1, curmethod2(par2 , method3(par3))) => return result

이렇게 input 파라미터를 1개만 받도록 나누는 것이다.

이러면 각각의 함수 method1,method2,method3 의 재사용이 가능해진다.

[c#] Closure Example2

static void Closures( ) {
Console.WriteLine(GetClosureFunction( )(30));
}

static Func GetClosureFunction( ) {
  int val = 10;
  Func internalAdd = x = > x + val;
    return internalAdd;
}


-------------

Console.WriteLine(GetClosureFunction( )(30)); 이부분을 보자.

GetClosureFunction( )(30)은

GetClosureFunction( )로 메소드는 끝이 나고,

Func internalAdd = x = > x + val; 을 리턴한다.

이때 이 internalAdd  는 메소드 안의 val 을 참조하기 때문에, 메소드가 끝났는데도, 이 메소드 안 val 가 살아 있는것이다.

Advantage of Closure

변수를 보호 할 수 있다.

즉, 클래스의 필드 멤버가 클래스의 함수에 쓰인다고 하자.

이 필드 멤버는 함수가 실행되기 전부터 초기화되고, 값이 지정된다.

그렇기 때문에, 중간에 이 값이 바뀌거나 했을경우 추적하기가 힘들어 진다.

즉, 디버깅이 복잡해 지게 된다.

어디서 이 필드멤버가 바뀌었는지 등등 고려해야될게 많아 진단 말이다.

따라서, 함수가 실행되고, 이 함수가 완전히 끝날떄까지만 지속되는 변수라면,

디버깅시, 이 함수에서 쓰이는 어던 수 (아까 예의 필드 멤버)는 함수 안에 로컬 변수로 있기 때문에, 디버깅이 매우 쉬워 진다.

이 테크닉을 클로저 라고 한다.

[C#] Closer Example

List list = new List();
            for ( int i = 0 ; i < 10 ; i++ )
            {
                list.Add( () => Console.WriteLine( i ) );
            }

list.ForEach(p=> p());


2016년 11월 7일 월요일

[Git] Basic step2

add file or edit file and..


1. git status : show what is changed in your repository

2. git add filename

3. git commit -m "message"

3. git push


[Git] Git basic - step1

1. install git

2.run gitbash

3. write down these

=> git config --global user.name ""


=> git config --global user.email ""