Posted by 우주여행가
,

유니코드 환경 (이 코드는 멀티바이트 환경에서도 사용 가능하다. 권장.)

 

//CString -> char* 는 CT2A

CString aaa = _T("AAAA");

char* bbb = new char[strlen(CT2A(aaa))+1];

strcpy(bbb, CT2A(aaa));

delete[] bbb;

 

 

//char* -> CString 는 CA2T

char* aaa = "AAAA";

CString bbb = CA2T(aaa);

 

 

멀티바이트 환경 (이 코드는 멀티바이트 환경에서만 사용할 수 있다.)

 

//CString -> char* 는 (LPSTR)(LPCTSTR)

CString aaa = _T("AAAA");

char* bbb = new char[strlen((LPSTR)(LPCTSTR)aaa)+1];

strcpy(bbb, (LPSTR)(LPCTSTR)aaa);

delete[] bbb;

 

 

//char* -> CString 는 (LPCTSTR)(LPSTR)

char* aaa = "AAAA";

CString bbb = (LPCTSTR)(LPSTR)aaa;

출처: http://darkstings.blog.me/30101840108

 

 

[출처] CString char*|작성자 9KM ArtOfRudah

Posted by 우주여행가
,
Posted by 우주여행가
,
.rc 파일을 열고자 하는데 opened in another editor 라는 메시지가 나오면서 열리지 않을때

solution explorer에서

 1) right click on resources.rc and select "view code" 
2) close resources.rc
3) right click on resource.h and select "view code"
4) close resource.h
5) select Build > Clean Solution
Posted by 우주여행가
,
#define swap(a,b) { tmp=(a); (a)=(b); (b)=tmp; }
#define swap1(a,b) { tmp1=(a); (a)=(b); (b)=tmp1; }
#define swap2(a,b) { tmp2=(a); (a)=(b); (b)=tmp2; }
#define swap3(a,b) { tmp3=(a); (a)=(b); (b)=tmp3; }
#define sinc(x) (((x)==0.0) ? (1.0) : (sin(x)/(x)))
#define sigmoid(x) (1.0/(1.0+exp(-(x))))

실수에 가장 가까운 정수
#define nint(x) (((x)>=0.0) ? ((int)((x)+0.5)):((int)((x)-0.5)))

#define modulus(x,mod) (((x)>=0) ? ((x)%(mod)):((abs(mod)-1)-((-(x)-1)%(mod))))
#define gray_level(red,green,blue) (0.299*(red)+0.587*(green)+0.114*(blue))

nint + clipping 
#define clip_nint(lower,upper,x) (((x)<(lower)) ? (lower):(min((upper),nint(x))))
#define clip(lower,upper,x) (((x)<(lower)) ? (lower):(min((upper),(x))))

#ifndef max
#define max(a,b)            (((a) > (b)) ? (a) : (b))
#endif

#ifndef min
#define min(a,b)            (((a) < (b)) ? (a) : (b))
#endif

추후 update 예정 
Posted by 우주여행가
,

'연구관련' 카테고리의 다른 글

읽어볼 논문  (0) 2011.08.09
Recognizing and Learning Object Categories  (0) 2011.08.03
내 논문이 흥미롭다는 외국인의 메일 ㅋㅋㅋ  (1) 2011.02.24
SiftGPU  (0) 2011.01.17
Computer Vision Open Source Algorithm Implementations  (0) 2010.12.03
Posted by 우주여행가
,
Dear ****-****:
   I have read your paper "Dynamic Range Compression Based on Statistical Analysis". I think it is a very good paper, especially about the edge check using different gamma processed images. I want to re-produce your experiment. I have generated the edge images based on the different gamma transform. But I am still NOT very clear about how to segment the pixels into three regions. Can you give me more (description, source code, refernece paper, etc) about it? Thank you very much!

Best Regards,
Robert
Mr Robert Yuan <yuan0827@yahoo.com.cn>


내 메일로 안왔었는데.. 내가 답장을 안했더니 (근데 왜 안온거지..)
2저자인 수정누나에게도 보냈다는 ㅋㅋ 암튼 기분은 좋다.. 알려달라는걸..알려줘야겠지?


Posted by 우주여행가
,

SiftGPU

연구관련 2011. 1. 17. 17:14
GPU로 SIFT 구현한 것
http://www.cs.unc.edu/~ccwu/siftgpu/
Posted by 우주여행가
,


using namespace std;
vector<int *> p;
vector<int *>::iterator i;

// (이하 생략)

i = p.begin();
while(i != p.end()) {
    delete[] (*i);
    p.erase(i);
    i++;
} p.clear();

위 코드는 메모리 누수를 남기게 된다. 이유는 다음과 같다.

p.push_back(0);
p.push_back(1);

i = p.begin();
cout << "Data : " << *i << endl;

i++;
cout << "Data : " << *i << endl;

i = p.begin();
p.erase(i);
cout << "Data : " << *i << endl;

result :
0
1
1

그러니까 erase 명령에서 원소를 지운 뒤 자동으로 한 칸 넘어간다. 그러니까 위의 코드에서는

i++ 을 하면 안된다는 것이다. 두 칸 넘어가는 꼴이 되니까. erase 명령에 의해 i가 실제로 1칸

넘어가는지에 대해서는 컴파일러 명세를 더 읽어봐야 하겠지만 erase된 iterator는 이전의 것이

아니라는 것만은 분명한 사실인데 i++ 이란 코드는 이전의 iterator 를 기준으로 하는 것이므로

어디선가 오류가 발생할 여지가 충분히 있는 것이다.



위 코드의 문제에 대한 해결 방법으로

while(i != p.end()) {
    delete[] (*i);
    i++;
} p.clear();

혹은

while(i != p.end()) {
    delete[] (*i);
    p.erase(i);
} p.clear();

같은 코드들이 제시되었는데, 전자가 여러모로 안정적이지 않을까?


그 외 capacity에 대한 말이 나왔는데, 적어도 gcc에서는 기 할당된 capacity에 대해서 erase나

clear이 capacity를 초기화 시키지는 않는 것 같았다. 그 외에는...... 원소를 삽입할 경우에는

capacity가 변하니까 미리 reserve 해 두고 삽입하는게 빠를지도 모르겠다.

vector<int> p;
vector<int>::iterator i;
cout << "Capacity : " << p.capacity() << endl;

for(int j = 0; j < 12; j++) p.push_back(j);
cout << "Capacity : " << p.capacity() << endl;

p.clear();
cout << "Capacity : " << p.capacity() << endl;

result :
0
16
16

VC++ 은 capacity가 날아가는 건가? 정확히는 모르겠음(집에 VC++ 이 없어 ㅠㅜ)
Posted by 우주여행가
,

출처는 밑에 있습니다.


vector에 저장된 요소를 루프를 돌며 일정 부분을 삭제하는 루틴은 쓰이는 곳이 많다.

 

보통 아래와 같이 이터레이터로 루프를 돌린다.

 

vector≪MyObj*≫ lists_;

vector≪MyObj*≫::iterator itr;

for ( itr = lists_.begin() ; itr != lists_.end() ; itr++ )

{

 MyObj* obj = *itr;

if ( 조건 )

{

 delete obj;obj=NULL;

lists_.erase(itr);

}

}

 

그런데, 그전까지 잘 동작하던 위 코드가 Visual studio 2008에서 작성할때는 때때로 오류가 발생하였다.

항상 발생하는 것은 아니고 때때로...

구글링을 통해서 해결책을 찾은것은 erase 결과로 이터레이터를 받는 식으로 고치는 것이다.

 

for ( itr = lists_.begin() ; itr != lists_.end() ; )

{

 MyObj* obj = *itr;

if ( 조건 )

{

 delete obj;obj=NULL;

itr = lists_.erase(itr);

}

else

 itr++;

}

 

위와 같이 하니까 때때로 발생하던 런타임 오류가 없어졌다...

이거때문에 며칠간 삽질 엄청 한거 생각하면

Posted by 우주여행가
,