私はopencv(オブジェクト認識用)をportaudioと組み合わせて、ビデオ入力に基づいてサウンドを再生しています。基本的に、私の目標は、あるピッチ/周波数の正弦波音を異なる速度で演奏することです。それは動作しますが、その結果は非常に予測不可能です。音声再生が動作しない(プログラムはゆっくり実行されますが動作します)、音声再生が行われない場合もあります。これは私のプログラムが行うことです:PortAudioとOpenCVを使用してオーディオの再生が一貫しないようにするにはどうすればよいですか?
ウェブカメラのフィードを開始 - >画像の領域を選択 - >ビデオフィードに戻る - > while(フレームが存在する) - >オブジェクトの位置を追跡 - >ポートオーディオツールを初期化する - >位置に基づいてサウンドを再生する - > Portaudioツールを終了する
なぜオーディオ再生が矛盾しているのか分かりません。あなたはすべてのヒントを持っていますか?私は周りを読んできましたが、私の考えはこれが待ち時間の問題であることですが、私は本当にこの問題で経験していません。私がopencvなしでportaudioを使用すると、レイテンシの問題は発生しないので、2つを組み合わせることと関係しています。どんな助けもありがとうございます。
while (frame)
{
cvCopyImage(frame, drawImg);
// process
track(frame);
// get result
CvRect r;
float confidence;
bool valid;
/* getRoi tells us if the region being tracked on the screen
* is the same region that we chose prior to entering this while loop
*/
getRoi(&r, &confidence, &valid);
// show
cvDrawRect(drawImg, cvPoint(r.x, r.y),
cvPoint(r.x + r.width - 1, r.y + r.height - 1),
valid ? cvScalar(0, 255, 0) : cvScalar(0, 255, 255),
2
);
writeLogo(drawImg,"USC-IRIS");
int xpos = r.x;
int ypos = r.y;
cvShowImage("Tracking", drawImg);
cout << "valid " << valid << endl;
cout << "conf val " << confidence << endl;
cout << "xpos, ypos " << xpos << ", " << ypos << endl;
//If the region on the screen is the region we chose
//then we should play specific sounds
if(valid){
sI->soundWrite(xpos, ypos);
float freq = sI->getFreq();
int amp = sI->getAmp();
float pulse = sI->getPulse();
switch(amp){
case 0:
//printf("Hear sound in both ears.\n");
data.targetBalance = .5;
break;
case 1:
//printf("Hear sound in left ear.\n");
data.targetBalance = 0;
break;
case 2:
//printf("Hear sound in right ear.\n");
data.targetBalance = 1;
break;
default:
//printf("Incorrect value for amp (left/right sound indicator)");
data.targetBalance = .5;
break;
}
err = Pa_Initialize(); //scan for available devices i.e. audio jack, headphones
if(err != paNoError) {
printf("init\n");
goto error;
}
//open the sound stream for processing
err = Pa_OpenDefaultStream(&stream, 0, 2, paFloat32, SAMPLE_RATE,
256, patestCallback, &data); //open the sound stream for processing
if(err != paNoError) {
printf("open\n");
goto error;
}
//start the stream (i.e. play sound) if no errors
err = Pa_StartStream(stream);
if(err != paNoError) {
printf("start\n");
goto error;
}
//check which ear(s) the sound should be played to
//hold that tone for a certain amount of time (pulse*200 millisec)
Pa_Sleep(pulse*200);
cout << "pulse: " << pulse << endl << "freq: " << freq << endl;
cout << "amp: " << amp << endl;
//stop the stream (i.e. stop playing sound)
err = Pa_StopStream(stream);
if(err != paNoError) {
printf("stop\n");
goto error;
}
err = Pa_CloseStream(stream);
if(err != paNoError) {
printf("close\n");
goto error;
}
err = Pa_Terminate();
if(err != paNoError) {
printf("term\n");
goto error;
}
}
int key = cvWaitKey(1);
// write
if (output_txt)
fprintf(output_txt, "%d %d %d %d\n", r.x, r.y, r.width, r.height);
if (output_avi)
cvWriteFrame(output_avi, drawImg);
// next
if (key == 'q'||key=='Q')
break;
frame = cvQueryFrame(capture);
}
これを行う際のCPUの負荷は?これはちょうど負荷の問題になることができますか?あなたがフレームレートを減らすとどうなりますか? –
フレームレート/ framesPerBuffの低下が助けにならなかったので、負荷ではありませんでした。私は問題を理解し、このページに投稿します。助けてくれてありがとう。 – nmante