
2012年4月6日
#define N 6

HANDLE hSuspend[N], hResume[N];
HANDLE hSuspend_one;
HANDLE hResume_one;

struct info


{
CRITICAL_SECTION ProtectSection;
int id;
int frames;
};


unsigned long __stdcall testFun(void *pContext)


{
info* pInfo = (info*)pContext;
while(1)

{
EnterCriticalSection(&pInfo->ProtectSection);
pInfo->frames++;
//printf("run sub Thread video %d frames %d\n", pInfo->id, pInfo->frames);
// DWORD rtn = WaitForSingleObject(hSuspend[pInfo->id], INFINITE);
DWORD rtn = WaitForSingleObject(hSuspend_one, INFINITE);
if (WAIT_OBJECT_0 == rtn)

{// 自己暫停自己
// printf("stop sub Thread video %d frames %d\n", pInfo->id, pInfo->frames);
WaitForSingleObject(hResume[pInfo->id], INFINITE);
//WaitForSingleObject(hResume_one, INFINITE);
}
LeaveCriticalSection(&pInfo->ProtectSection);
}
return 0;
}


int main()


{
DWORD thid;
HANDLE hand[N];
int mainframes = 0;
info myInfo[N];

hSuspend_one = CreateEvent(NULL, TRUE, FALSE, NULL);
for(int i = 0; i < N; i++)

{
hSuspend[i] = CreateEvent(NULL, TRUE, FALSE, NULL);
hResume[i] = CreateEvent(NULL, FALSE, FALSE, NULL);
myInfo[i].id = i;
myInfo[i].frames = 0;
InitializeCriticalSection(&myInfo[i].ProtectSection);
}
for(int i = 0; i < N; i++)

{
hand[i] = CreateThread( NULL, NULL, testFun, &myInfo[i], CREATE_SUSPENDED, &thid);
}

for(int i = 0; i < N; i++)

{
ResumeThread(hand[i]);
}
while(1)

{
printf("main thread frames %d\n", ++mainframes);

/**//*for(int i = 0; i < N; i++)
{
SetEvent(hSuspend[i]);
}*/
SetEvent(hSuspend_one);
Sleep(5);
for(int i = 0; i < N; i++)

{
printf("main thread video %d frames %d\n",myInfo[i].id,myInfo[i].frames);
}
printf("\n");
for(int i = 0; i < N; i++)

{
SetEvent(hResume[i]);
}
}
for(int i = 0; i < N; i++)

{
WaitForSingleObject(hand[i], INFINITE);
DeleteCriticalSection( &myInfo[i].ProtectSection);
CloseHandle(hand[i]);
CloseHandle(hResume[i]);
CloseHandle(hSuspend[i]);
}
CloseHandle(hSuspend_one);
return 0;
}
posted @
2012-04-06 13:32 noBugnoGain 閱讀(994) |
評論 (0) |
編輯 收藏

2009年12月28日
1
#include <cutil_inline.h>
2
#include <cv.h>
3
#include <cstdio>
4
#include <iostream>
5
#include <cutil.h>
6
#include <ctime>
7
#include <cstdlib>
8
#include <highgui.h>
9
#include <windows.h>
10
11
#pragma comment(lib, "cuda.lib")
12
#pragma comment(lib, "cudart.lib")
13
#pragma comment(lib, "cutil32.lib")
14
#pragma comment(lib, "cv.lib")
15
#pragma comment(lib, "cxcore.lib")
16
#pragma comment(lib, "highgui.lib")
17
18
using namespace std;
19
20
__global__ void mainKernel(unsigned char *d_data, int widthStep, int width, int height)
21

{
22
unsigned int x = blockIdx.x*blockDim.x+threadIdx.x;
23
unsigned int y = blockIdx.y*blockDim.y+threadIdx.y;
24
if( x>0 && x < width && y>0 && y < height )
25
{
26
d_data[y*widthStep+x*3+0] ^= ( ((x&0x0F)==0) ^ ((y&0x0F)==0) ) *255;
27
d_data[y*widthStep+x*3+1] ^= ( ((x&0x0F)==0) ^ ((y&0x0F)==0) ) *255;
28
d_data[y*widthStep+x*3+2] ^= ( ((x&0x0F)==0) ^ ((y&0x0F)==0) ) *255;
29
}
30
}
31
32
int main()
33

{
34
IplImage* src = cvLoadImage("IMG_03.JPG");
35
36
int widthStep = src->widthStep;
37
int width = src->width;
38
int height = src->height;
39
40
printf("before widthStep = %d\n", widthStep);
41
if( widthStep%4 != 0)
42
{
43
widthStep = (1+widthStep/4)*4;
44
}
45
printf("after widthStep = %d\n", widthStep);
46
47
unsigned char* d_img_data;
48
CUDA_SAFE_CALL(cudaMalloc((void**)&d_img_data, widthStep*height));
49
CUDA_SAFE_CALL(cudaMemcpy(d_img_data, src->imageData, widthStep*height, cudaMemcpyHostToDevice));
50
51
dim3 dimBlock(16, 16, 1);
52
dim3 dimGrid( (width+dimBlock.x-1)/dimBlock.x, (height+dimBlock.y-1)/dimBlock.y );
53
mainKernel<<<dimGrid, dimBlock, 0>>>(d_img_data, widthStep, width, height);
54
CUDA_SAFE_CALL(cudaThreadSynchronize());
55
56
CUDA_SAFE_CALL( cudaMemcpy( src->imageData, d_img_data, widthStep*height, cudaMemcpyDeviceToHost) );
57
58
cvNamedWindow("test",CV_WINDOW_AUTOSIZE);
59
cvShowImage("test",src);
60
cvWaitKey(0);
61
cvDestroyAllWindows();
62
63
cvReleaseImage(&src);
64
CUDA_SAFE_CALL(cudaFree(d_img_data));
65
return 0;
66
}
posted @
2009-12-28 10:58 noBugnoGain 閱讀(1795) |
評論 (1) |
編輯 收藏

2009年12月25日
摘要: 1#include <cutil_inline.h> 2#include <cv.h> 3#include <cstdio> 4#include <iostream> 5#include &...
閱讀全文
posted @
2009-12-25 10:48 noBugnoGain 閱讀(4953) |
評論 (9) |
編輯 收藏

2009年7月4日
GSS and DoG scale space structures
GSS:Gaussian scale space(高斯尺度空間)
DoG: Difference of Gaussians(高斯差分)
octave index:層索引
scale index:尺度索引
建立圖像的高斯尺度空間其實就是用高斯核對圖像進行卷積,一層一層的平滑圖像,一層又分若干個scale. 每個scale的采樣步長為:

建立好高斯尺度空間后,再通過建立高斯差分尺度空間尋找圖像的局部極值。高斯差分尺度空間建立很簡單,對高斯尺度空間的連續圖像相減就可以了。具體公式如下:
.
極值的確定如圖:

在圖像高斯差分尺度空間內當前尺度和其相鄰兩個尺度3*3的區域內,標記的X和其他26個像素比較,如果X的灰度大于或者小于其他26個像素。那么這個X就是個極值。
建立高斯尺度空間有些細節的問題,具體可以看David G.low的論文。
posted @
2009-07-04 13:09 noBugnoGain 閱讀(4870) |
評論 (3) |
編輯 收藏

2009年5月13日
那些年,白云悠悠,長空萬里。
那些年,青澀嚴肅,理想高遠。
那些年,青山巍峨,松柏濤濤。
那些年,笑聲盈盈,高談闊論。
那些年,白墻青瓦,綠地紅花。
那些年,白衣女子,君子好逑。
那些事兒,那些年的事兒,都離我們漸漸遠去。就讓她去吧,帶著她的美麗和笑容,帶著她的寬容和博愛。
逝去之所以美麗,那些年,那些事兒都不再來。
posted @
2009-05-13 19:02 noBugnoGain 閱讀(413) |
評論 (3) |
編輯 收藏

2009年4月25日
一夜,酣睡,朦朦中回我故里,山青水秀,吾似一仙人,浮于半空,天下美色盡現眼底。心暢然。忽然,宇宙變更,四季失常,一會兒春意盎然,一會兒白雪鎧鎧。心驟緊。霎那星球崩裂,消失殆盡。吾似一塵粒游離于三界之外。一種興奮之感充溢于懷,難道這是太虛幻境,環視四周,黑暗中閃爍中其他星球的淚光,吾明之:地球亡亦。茫茫宇宙獨我存之,一種莫名的失落襲來。我親人在那里,我父母在那里,各種疑問隨之而來。憂愁感來,不,我要找到你們!好像在水中掙扎,對岸邊的渴望。也許我這個塵粒感動更高智慧的生命。救我上了一只宇宙中的諾亞之舟。此舟很簡易。就一懸于宇宙中平板。在此環視四周。星星點點,故土不在。天明,心舒然,都還在!
posted @
2009-04-25 21:36 noBugnoGain 閱讀(357) |
評論 (2) |
編輯 收藏