第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

求問(wèn)一個(gè)多線程的例程C++(API),情況如下所示:

求問(wèn)一個(gè)多線程的例程C++(API),情況如下所示:

慕桂英546537 2021-11-20 15:11:49
#include "stdafx.h"#include "CameraDS.h"#include "string"#include <cv.h>#include <highgui.h>#include <stdio.h>#include <iostream>#include "windows.h"#include <fstream>using namespace std; int singlematching(IplImage *srcl, IplImage *srcr , IplImage *tp1);int main() {int cam_count;//僅僅獲取攝像頭數(shù)目cam_count = CCameraDS::CameraCount();printf("There are %d cameras.\n", cam_count);//獲取所有攝像頭的名稱for(int i=0; i < cam_count; i++){char camera_name[1024]; int retval = CCameraDS::CameraName(i, camera_name, sizeof(camera_name) );if(retval >0)printf("Camera #%d's Name is '%s'.\n", i, camera_name);elseprintf("Can not get Camera #%d's name.\n", i);}if(cam_count==0)return -1;// 創(chuàng)建2個(gè)攝像頭類CCameraDS camera1;CCameraDS camera2; if(! camera1.OpenCamera(0, false)) {fprintf(stderr, "Can not open camera.\n");return -1;}//打開第二個(gè)攝像頭camera2.OpenCamera(1, false); cvNamedWindow("cam1",1);cvNamedWindow("cam2",1);int nFrmNum = 0;int k=0;while(1){//獲取一幀IplImage *pFrame1 = camera1.QueryFrame();IplImage *pFrame2 = camera2.QueryFrame();IplImage *fFrame1 = 0;IplImage *fFrame2 = 0;float scale=0.2;CvSize dst_cvsize;dst_cvsize.width=pFrame1->width*scale;dst_cvsize.height=pFrame1->height*scale;fFrame1=cvCreateImage(dst_cvsize,pFrame1->depth,pFrame1->nChannels);fFrame2=cvCreateImage(dst_cvsize,pFrame1->depth,pFrame1->nChannels);cvResize(pFrame1,fFrame1,CV_INTER_LINEAR);cvResize(pFrame2,fFrame2,CV_INTER_LINEAR);nFrmNum++;DWORD dwStart = GetTickCount();DWORD dwEnd = dwStart;do{dwEnd = GetTickCount()-dwStart;}while(dwEnd <1);// 顯示實(shí)時(shí)的攝像頭視頻cvShowImage("cam1", fFrame1);cvShowImage("cam2", fFrame2);IplImage *tp1 = cvLoadImage("tr.bmp",1); int m;if(k==5){m=singlematching( pFrame2, pFrame1,tp1);\\運(yùn)算k=0;}k++;//cvWaitKey(33);int key = cvWaitKey(33);if( key == 27 ) break;}camera1.CloseCamera(); //可不調(diào)用此函數(shù),CCameraDS析構(gòu)時(shí)會(huì)自動(dòng)關(guān)閉攝像頭camera2.CloseCamera();cvDestroyAllWindows();return 0;}int singlematching(IplImage *srcl, IplImage *srcr ,IplImage *tp1){}
查看完整描述

2 回答

?
慕妹3242003

TA貢獻(xiàn)1824條經(jīng)驗(yàn) 獲得超6個(gè)贊

#include <windows.h>

typedef HANDLE HSEMAPHORE;

#define P(hHandle) ::WaitForSingleObject(hHandle, INFINITE)
#define V(hHandle) ::ReleaseSemaphore(hHandle, 1, NULL)
#define Semaphore(lInitial, lMaximum) ::CreateSemaphore(NULL, lInitial, lMaximum, NULL)
#define Thread(lpProc, lpParam) ::CreateThread(NULL, 0, lpProc, (LPVOID)lpParam, 0, NULL)
#define Wait(nCount, lpHandles) ::WaitForMultipleObjects(nCount, lpHandles, TRUE, INFINITE)

HSEMAPHORE n = Semaphore(0, 1);
HSEMAPHORE s = Semaphore(1, 1);
HSEMAPHORE e = Semaphore(100, 100);

UINT count = 0;

void Produce()
void Consume()

DWORD WINAPI Producer(LPVOID lpParameter)
{
while (true)
{
Produce();
P(e);
P(s);
count++;
printf("Producer: %d\n", count);
V(s);
V(n);
}
return 0;
}

DWORD WINAPI Consumer(LPVOID lpParameter)
{
while (true)
{
P(n);
P(s);
count--;
printf("Consumer: %d\n", count);
V(s);
V(e);
Consume();
}
return 0;
}

int main()
{
HANDLE hThreads[2];

hThreads[0] = Thread(Producer, (LPVOID)NULL);
hThreads[1] = Thread(Consumer, (LPVOID)NULL);

Wait(2, hThreads);
return 0;
}



查看完整回答
反對(duì) 回復(fù) 2021-11-24
?
ABOUTYOU

TA貢獻(xiàn)1812條經(jīng)驗(yàn) 獲得超5個(gè)贊

首先,你要有一個(gè)概念,多線程只是在有CPU空閑的程序中實(shí)現(xiàn)多個(gè)線程并行,從而使程序顯得更”流暢“。多線程并不會(huì)讓你的CPU運(yùn)算能力得到提高。
你的程序,或許可以用雙線程:
一個(gè)線程捕捉圖像,一個(gè)線程處理數(shù)據(jù)。但要記住兩點(diǎn):
1,兩個(gè)線程間要加緩存
2,當(dāng)緩存已經(jīng)滿了的時(shí)候,捕捉線程應(yīng)該要等處理數(shù)據(jù)的線程處理完緩存才繼續(xù)捕捉。
因此,并不能保證你用了雙線程就會(huì)更加流暢,要你的的電腦運(yùn)算能力。和捕捉圖像的數(shù)據(jù)大小。

查看完整回答
反對(duì) 回復(fù) 2021-11-24
  • 2 回答
  • 0 關(guān)注
  • 326 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)