
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 阅读(990) |
评论 (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 阅读(1791) |
评论 (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 阅读(4949) |
评论 (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 阅读(4868) |
评论 (3) |
编辑 收藏

2009年5月13日
那些年,白云悠悠,长空万里。
那些年,青涩严肃,理想高远。
那些年,青山巍峨,松柏涛涛。
那些年,笑声盈盈,高谈阔论。
那些年,白墙青瓦,绿地红花。
那些年,白衣女子,君子好逑。
那些事儿,那些年的事儿,都离我们渐渐远去。就让她去吧,带着她的美丽和笑容,带着她的宽容和博爱。
逝去之所以美丽,那些年,那些事儿都不再来。
posted @
2009-05-13 19:02 noBugnoGain 阅读(408) |
评论 (3) |
编辑 收藏

2009年4月25日
一夜,酣睡,朦朦中回我故里,山青水秀,吾似一仙人,浮于半空,天下美色尽现眼底。心畅然。忽然,宇宙变更,四季失常,一会儿春意盎然,一会儿白雪铠铠。心骤紧。霎那星球崩裂,消失殆尽。吾似一尘粒游离于三界之外。一种兴奋之感充溢于怀,难道这是太虚幻境,环视四周,黑暗中闪烁中其他星球的泪光,吾明之:地球亡亦。茫茫宇宙独我存之,一种莫名的失落袭来。我亲人在那里,我父母在那里,各种疑问随之而来。忧愁感来,不,我要找到你们!好像在水中挣扎,对岸边的渴望。也许我这个尘粒感动更高智慧的生命。救我上了一只宇宙中的诺亚之舟。此舟很简易。就一悬于宇宙中平板。在此环视四周。星星点点,故土不在。天明,心舒然,都还在!
posted @
2009-04-25 21:36 noBugnoGain 阅读(356) |
评论 (2) |
编辑 收藏