void CMask::NewMask ( PPCMask Mask, int nMasks ) { int i,nlen; word w; ClearMask(); if (Mask && (nMasks>0)) { nlen = 0; w = 0; while (w==0) { for (i=0;i<nMasks;i++) if (Mask[i]) { if (nlen<Mask[i]->mlen) w |= Mask[i]->m[nlen]; } nlen++; w = ~w; } Expand ( nlen ); i = nlen-1; m[i] = 1; while (!(m[i] & w)) m[i] <<= 1; } else { Expand ( 1 ); m[0] = 1; } }
void CMask::SelMask ( PCMask Mask ) { int i,l; if (Mask) { l = IMin(mlen,Mask->mlen); for (i=0;i<l;i++) m[i] &= Mask->m[i]; for (i=l;i<mlen;i++) m[i] = 0; } else ClearMask(); }
void CMask::CopyMask ( PCMask Mask ) { int i; if (mlen!=Mask->mlen) ClearMask(); if (Mask) { mlen = Mask->mlen; if (mlen>0) { m = new word[mlen]; for (i=0;i<mlen;i++) m[i] = Mask->m[i]; } } }
/* ***************************************************************************** **函 数 名:void GatherData(void) **功能描述:数据采集 **输 入:无 **输 出:无 ***************************************************************************** */ void GatherData(void) { //ACCEL_Init(); if(SysDat.flagGather == 0) //如果不要数据采集直接退出 { return; } if(ReadMask(SysDat.Flag,SYS_BE_WORKING) == SYS_BE_WORKING) //开始数据采集 { ClearMask(SysDat.Flag,SYS_BE_WORKING); InitTimer3(); Timer3IntSwitchOn(); GatherVariable(); } if(SysDat.flagGather == 1) { //Timer3Open(); while(SysDat.flagGather != 2) //等待电压和温度数据采集完成 { if(!SysDat.timeLeft) { if(!AD0BUSY) { ADC0_Converx(VOLTAGE); ADC0_Converx(TEMPERATURE); if(SysDat.pFilter>=5) { SysDat.pFilter = 0; ParDat.voltage = (Uint8)(Filter(GatDat->TempLoad,5)>>2); //取ADC高8位 ParDat.temperature = (Uint8)(Filter(GatDat->TempAcc,5)>>2); //取ADC高8位 SysDat.flagGather = 2; break; } SysDat.timeLeft = 10; Timer3Open(); } } PCON |= 0x01; //空闲方式(省电),由Timer3中断唤醒 }
void Renderer::clear() { clear(ClearMask(COLOUR_BUFFER | DEPTH_BUFFER | STENCIL_BUFFER)); }
CMask::~CMask() { ClearMask(); }
int _tmain(int argc, _TCHAR* argv[]) { /* Начальная инициализация параметров. этот код требуется запустить один раз. TVAInitParams params; memcpy(¶ms.Camera, &g_camera, sizeof(TVACamera)); params.NumZones = 0; params.EventSens = 0.5; params.EventTimeSens = 1000; SaveInitParams("params.xml", ¶ms); */ // инициализация зон наблюдения. for (int i = 0; i < C_MAX_OBJECTS; i++) { g_contours[i].IsRect = false; g_contours[i].NumPoints = C_MAX_POINTS; g_contours[i].Points = (TVAPoint*)malloc(C_MAX_POINTS*sizeof(TVAPoint)); } cvInitFont(&g_font, CV_FONT_HERSHEY_PLAIN,1, 1); CvCapture* capture = NULL; if (argc < 2) capture = cvCaptureFromCAM(0); else capture = cvCaptureFromFile(argv[1]); if (capture == NULL) { printf("%s\n", "Cannot open camera."); return -1; } double fps = cvGetCaptureProperty ( // Получаем частоту кадров capture, CV_CAP_PROP_FPS ); CvSize size = cvSize( // Получаем размер (int)cvGetCaptureProperty( capture, CV_CAP_PROP_FRAME_WIDTH), (int)cvGetCaptureProperty( capture, CV_CAP_PROP_FRAME_HEIGHT) ); g_mask = cvCreateImage(size, IPL_DEPTH_8U, 1); CvVideoWriter* writer = NULL; cvNamedWindow(_MODULE_); cvSetMouseCallback(_MODULE_, on_mouse); /* Цикл получения и обработки изображения. */ for (;;) { IplImage* frame = NULL; frame = cvQueryFrame(capture); if (!frame) break; /* отрисовка прямоугольников */ for (int i = 0; i < g_rects_count; i++) { CvPoint p1 = cvPoint(g_rects[i].x, g_rects[i].y); CvPoint p2 = cvPoint(p1.x + g_rects[i].width, p1.y + g_rects[i].height); cvRectangle(frame, p1, p2, CV_RGB(255,0,0)); } /* Отрисовка зон наблюдения. */ for (int i = 0; i < g_contours_count; i++) { if (g_contours[i].NumPoints > 0) { for (int j = 1; j < g_contours[i].NumPoints; j++) { CvPoint p1 = cvPoint((int)g_contours[i].Points[j-1].X, (int)g_contours[i].Points[j-1].Y); CvPoint p2 = cvPoint((int)g_contours[i].Points[j].X, (int)g_contours[i].Points[j].Y); cvLine(frame, p1,p2, CV_RGB(255,0,0)); } CvPoint p1 = cvPoint((int)g_contours[i].Points[g_contours[i].NumPoints-1].X, (int)g_contours[i].Points[g_contours[i].NumPoints-1].Y); CvPoint p2 = cvPoint((int)g_contours[i].Points[0].X, (int)g_contours[i].Points[0].Y); cvLine(frame, p1,p2, CV_RGB(255,0,0)); } } /* Отображение полученного изображения в окне. */ ProcessFrame(frame); if (g_grid_visible) DrawGrid(frame); DrawStatus(frame); cvShowImage(_MODULE_, frame); /* Запись фрейма */ if (g_record_video) cvWriteFrame( writer, frame ); /* Анализ клавиатуры */ bool state = g_set_rects || g_set_contours || g_set_zones; int c; c = cvWaitKey(10); if ((char)c == 27) break; if ((char)c == 's') { cvSaveImage("out.png", frame); } else if ((char)c == 'l') { if (!state) LoadRects(size.width, size.height); } else if ((char)c == 'g') { if (!state) LoadContours(size.width, size.height); } else if ((char)c == 'k') { if (!state) LoadZones(size.width, size.height); } else if ((char)c == 'r') { if (g_record_video) { // завершаем запись на диск cvReleaseVideoWriter( &writer ); writer = NULL; g_record_video = false; printf("Stop recording.\n"); } else { // открываем файл для записи и связываем с ним // переменную writer writer = cvCreateVideoWriter("out.avi",CV_FOURCC('D','I','V','X'), fps, size ); if (writer == NULL) { printf("%s\n", "Cannot create writer."); } else { g_record_video = true; printf("Start recording.\n"); } } } else if ((char)c == 't') { if (g_set_rects) { SaveRects(size.width, size.height); if (!g_set_zones) { g_rects_count = 0; ClearMask(g_mask); } g_set_rects = false; } else if (!g_set_contours) { g_set_rects = true; } } else if ((char)c == 'c') { if (g_set_contours) { SaveContours(size.width, size.height); if (!g_set_zones) { g_contours_count = 0; ClearMask(g_mask); } g_set_contours = false; g_open_contour = false; } else if (!g_set_rects) { g_set_contours = true; } } else if ((char)c == 'z') { if (g_set_zones) { SaveZones(size.width, size.height); g_set_zones = false; g_contours_count = 0; g_rects_count = 0; ClearMask(g_mask); } else if (!g_set_rects && !g_set_contours) { g_set_zones = true; } } else if ((char)c == 'w') { g_grid_visible = !g_grid_visible; } } cvReleaseVideoWriter( &writer ); cvDestroyWindow(_MODULE_); cvReleaseCapture(&capture); cvReleaseImage(&g_mask); // освобождение памяти for (int i = 0; i < C_MAX_OBJECTS; i++) { free(g_contours[i].Points); } return 0; }