Ejemplo n.º 1
0
Archivo: display.cpp Proyecto: lm92/CG
void myDisplay() {

  GLdouble x = TORUS_INIT_X, y = TORUS_INIT_Y, z = TORUS_INIT_Z;

  
  glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
  
  glClear(GL_COLOR_BUFFER_BIT);

  createSquare(TABLE_X, TABLE_Y, TABLE_Z, TABLE_RAD);

  glPushMatrix();
  
  createTrack(x, y, z);

  glPopMatrix();

  glPushMatrix();

  x += TRACK_SIZE;
  
  createTrack(x, y, z);

  glPopMatrix();

  glFlush();


}
Ejemplo n.º 2
0
void K3b::AudioDoc::addTracks( const QList<QUrl>& urls, int position )
{
    QList<QUrl> allUrls = extractUrlList( K3b::convertToLocalUrls(urls) );
    QList<QUrl>::iterator end( allUrls.end());
    for( QList<QUrl>::iterator it = allUrls.begin(); it != end; it++, position++ ) {
        QUrl& url = *it;
        if( url.toLocalFile().right(3).toLower() == "cue" ) {
            // try adding a cue file
            if( K3b::AudioTrack* newAfter = importCueFile( url.toLocalFile(), getTrack(position) ) ) {
                position = newAfter->trackNumber();
                continue;
            }
        }

        if( K3b::AudioTrack* track = createTrack( url ) ) {
            addTrack( track, position );

            K3b::AudioDecoder* dec = static_cast<K3b::AudioFile*>( track->firstSource() )->decoder();
            track->setTitle( dec->metaInfo( K3b::AudioDecoder::META_TITLE ) );
            track->setArtist( dec->metaInfo( K3b::AudioDecoder::META_ARTIST ) );
            track->setSongwriter( dec->metaInfo( K3b::AudioDecoder::META_SONGWRITER ) );
            track->setComposer( dec->metaInfo( K3b::AudioDecoder::META_COMPOSER ) );
            track->setCdTextMessage( dec->metaInfo( K3b::AudioDecoder::META_COMMENT ) );
        }
    }

    emit changed();
}
Ejemplo n.º 3
0
jobject getJavaTrack(JNIEnv* env, jobject parentJavaHEIF, void* nativeObject)
{
    if (nativeObject != NULL)
    {
        HEIFPP::Track* nativeItem = (HEIFPP::Track*) nativeObject;
        return createTrack(env, parentJavaHEIF, nativeItem);
    }
    else
    {
        return NULL;
    }
}
Ejemplo n.º 4
0
Album* ResponseDecoder::assembleAlbum(const QJsonObject& albumJson, Artist* artist)
{
	// Creating album from json
	Album* album = createAlbum(albumJson, artist);

	// Looking for tracks in json
	QJsonArray trackArray = albumJson["tracks"].toArray();

	foreach (const QJsonValue& trackJsonValue, trackArray) {

		// Creating track from json
		Track* track = createTrack(trackJsonValue.toObject(), album);

		// Adding track to album
		album->addTrack(track);
	}
Ejemplo n.º 5
0
status_t AudioTrack::obtainBuffer(Buffer* audioBuffer, int32_t waitCount)
{
    int active;
    status_t result;
    audio_track_cblk_t* cblk = mCblk;
    uint32_t framesReq = audioBuffer->frameCount;
    uint32_t waitTimeMs = (waitCount < 0) ? cblk->bufferTimeoutMs : WAIT_PERIOD_MS;

    audioBuffer->frameCount  = 0;
    audioBuffer->size = 0;

    uint32_t framesAvail = cblk->framesAvailable();

    if (framesAvail == 0) {
        cblk->lock.lock();
        goto start_loop_here;
        while (framesAvail == 0) {
            active = mActive;
            if (UNLIKELY(!active)) {
                LOGV("Not active and NO_MORE_BUFFERS");
                cblk->lock.unlock();
                return NO_MORE_BUFFERS;
            }
            if (UNLIKELY(!waitCount)) {
                cblk->lock.unlock();
                return WOULD_BLOCK;
            }
            if (!(cblk->flags & CBLK_INVALID_MSK)) {
                result = cblk->cv.waitRelative(cblk->lock, milliseconds(waitTimeMs));
            }
            if (cblk->flags & CBLK_INVALID_MSK) {
                LOGW("obtainBuffer() track %p invalidated, creating a new one", this);
                // no need to clear the invalid flag as this cblk will not be used anymore
                cblk->lock.unlock();
                goto create_new_track;
            }
            if (__builtin_expect(result!=NO_ERROR, false)) {
                cblk->waitTimeMs += waitTimeMs;
                if (cblk->waitTimeMs >= cblk->bufferTimeoutMs) {
                    // timing out when a loop has been set and we have already written upto loop end
                    // is a normal condition: no need to wake AudioFlinger up.
                    if (cblk->user < cblk->loopEnd) {
                        LOGW(   "obtainBuffer timed out (is the CPU pegged?) %p "
                                "user=%08x, server=%08x", this, cblk->user, cblk->server);
                        //unlock cblk mutex before calling mAudioTrack->start() (see issue #1617140)
                        cblk->lock.unlock();
                        result = mAudioTrack->start();
                        if (result == DEAD_OBJECT) {
                            LOGW("obtainBuffer() dead IAudioTrack: creating a new one");
create_new_track:
                            result = createTrack(mStreamType, cblk->sampleRate, mFormat, mChannelCount,
                                                 mFrameCount, mFlags, mSharedBuffer, getOutput(), false);
                            if (result == NO_ERROR) {
                                cblk = mCblk;
                                cblk->bufferTimeoutMs = MAX_RUN_TIMEOUT_MS;
                                mAudioTrack->start();
                            }
                        }
                        cblk->lock.lock();
                    }
                    cblk->waitTimeMs = 0;
                }

                if (--waitCount == 0) {
                    cblk->lock.unlock();
                    return TIMED_OUT;
                }
            }
            // read the server count again
        start_loop_here:
            framesAvail = cblk->framesAvailable_l();
        }
        cblk->lock.unlock();
    }

    // restart track if it was disabled by audioflinger due to previous underrun
    if (cblk->flags & CBLK_DISABLED_MSK) {
        cblk->flags &= ~CBLK_DISABLED_ON;
        LOGW("obtainBuffer() track %p disabled, restarting", this);
        mAudioTrack->start();
    }

    cblk->waitTimeMs = 0;

    if (framesReq > framesAvail) {
        framesReq = framesAvail;
    }

    uint32_t u = cblk->user;
    uint32_t bufferEnd = cblk->userBase + cblk->frameCount;

    if (u + framesReq > bufferEnd) {
        framesReq = bufferEnd - u;
    }

    audioBuffer->flags = mMuted ? Buffer::MUTE : 0;
    audioBuffer->channelCount = mChannelCount;
    audioBuffer->frameCount = framesReq;
    audioBuffer->size = framesReq * cblk->frameSize;
    if (AudioSystem::isLinearPCM(mFormat)) {
        audioBuffer->format = AudioSystem::PCM_16_BIT;
    } else {
        audioBuffer->format = mFormat;
    }
    audioBuffer->raw = (int8_t *)cblk->buffer(u);
    active = mActive;
    return active ? status_t(NO_ERROR) : status_t(STOPPED);
}
Ejemplo n.º 6
0
void AudioTrack::start()
{
    sp<AudioTrackThread> t = mAudioTrackThread;
    status_t status;

    LOGV("start %p", this);
    if (t != 0) {
        if (t->exitPending()) {
            if (t->requestExitAndWait() == WOULD_BLOCK) {
                LOGE("AudioTrack::start called from thread");
                return;
            }
        }
        t->mLock.lock();
     }

    if (android_atomic_or(1, &mActive) == 0) {
        mNewPosition = mCblk->server + mUpdatePeriod;
        mCblk->bufferTimeoutMs = MAX_STARTUP_TIMEOUT_MS;
        mCblk->waitTimeMs = 0;
        mCblk->flags &= ~CBLK_DISABLED_ON;
        if (t != 0) {
           t->run("AudioTrackThread", THREAD_PRIORITY_AUDIO_CLIENT);
        } else {
            setpriority(PRIO_PROCESS, 0, THREAD_PRIORITY_AUDIO_CLIENT);
        }

        if (mCblk->flags & CBLK_INVALID_MSK) {
            LOGW("start() track %p invalidated, creating a new one", this);
            // no need to clear the invalid flag as this cblk will not be used anymore
            // force new track creation
            status = DEAD_OBJECT;
        } else {
            status = mAudioTrack->start();
        }
        if (status == DEAD_OBJECT) {
            LOGV("start() dead IAudioTrack: creating a new one");
            status = createTrack(mStreamType, mCblk->sampleRate, mFormat, mChannelCount,
                                 mFrameCount, mFlags, mSharedBuffer, getOutput(), false);
            if (status == NO_ERROR) {
                status = mAudioTrack->start();
                if (status == NO_ERROR) {
                    mNewPosition = mCblk->server + mUpdatePeriod;
                }
            }
        }
        if (status != NO_ERROR) {
            LOGV("start() failed");
            android_atomic_and(~1, &mActive);
            if (t != 0) {
                t->requestExit();
            } else {
                setpriority(PRIO_PROCESS, 0, ANDROID_PRIORITY_NORMAL);
            }
        }
    }

    if (t != 0) {
        t->mLock.unlock();
    }
}
Ejemplo n.º 7
0
status_t AudioTrack::set(
        int streamType,
        uint32_t sampleRate,
        int format,
        int channels,
        int frameCount,
        uint32_t flags,
        callback_t cbf,
        void* user,
        int notificationFrames,
        const sp<IMemory>& sharedBuffer,
        bool threadCanCallJava,
        int sessionId)
{

    LOGV_IF(sharedBuffer != 0, "sharedBuffer: %p, size: %d", sharedBuffer->pointer(), sharedBuffer->size());

    if (mAudioTrack != 0) {
        LOGE("Track already in use");
        return INVALID_OPERATION;
    }

    int afSampleRate;
    if (AudioSystem::getOutputSamplingRate(&afSampleRate, streamType) != NO_ERROR) {
        return NO_INIT;
    }
    uint32_t afLatency;
    if (AudioSystem::getOutputLatency(&afLatency, streamType) != NO_ERROR) {
        return NO_INIT;
    }

    // handle default values first.
    if (streamType == AudioSystem::DEFAULT) {
        streamType = AudioSystem::MUSIC;
    }
    if (sampleRate == 0) {
        sampleRate = afSampleRate;
    }
    // these below should probably come from the audioFlinger too...
    if (format == 0) {
        format = AudioSystem::PCM_16_BIT;
    }
    if (channels == 0) {
        channels = AudioSystem::CHANNEL_OUT_STEREO;
    }

    // validate parameters
    if (!AudioSystem::isValidFormat(format)) {
        LOGE("Invalid format");
        return BAD_VALUE;
    }

    // force direct flag if format is not linear PCM
    if (!AudioSystem::isLinearPCM(format)) {
        flags |= AudioSystem::OUTPUT_FLAG_DIRECT;
    }

    if (!AudioSystem::isOutputChannel(channels)) {
        LOGE("Invalid channel mask");
        return BAD_VALUE;
    }
    uint32_t channelCount = AudioSystem::popCount(channels);

    audio_io_handle_t output = AudioSystem::getOutput((AudioSystem::stream_type)streamType,
            sampleRate, format, channels, (AudioSystem::output_flags)flags);

    if (output == 0) {
        LOGE("Could not get audio output for stream type %d", streamType);
        return BAD_VALUE;
    }

    mVolume[LEFT] = 1.0f;
    mVolume[RIGHT] = 1.0f;
    mSendLevel = 0;
    mFrameCount = frameCount;
    mNotificationFramesReq = notificationFrames;
    mSessionId = sessionId;
    mAuxEffectId = 0;

    // create the IAudioTrack
    status_t status = createTrack(streamType, sampleRate, format, channelCount,
                                  frameCount, flags, sharedBuffer, output, true);

    if (status != NO_ERROR) {
        return status;
    }

    if (cbf != 0) {
        mAudioTrackThread = new AudioTrackThread(*this, threadCanCallJava);
        if (mAudioTrackThread == 0) {
          LOGE("Could not create callback thread");
          return NO_INIT;
        }
    }

    mStatus = NO_ERROR;

    mStreamType = streamType;
    mFormat = format;
    mChannels = channels;
    mChannelCount = channelCount;
    mSharedBuffer = sharedBuffer;
    mMuted = false;
    mActive = 0;
    mCbf = cbf;
    mUserData = user;
    mLoopCount = 0;
    mMarkerPosition = 0;
    mMarkerReached = false;
    mNewPosition = 0;
    mUpdatePeriod = 0;
    mFlags = flags;

    return NO_ERROR;
}
// functie de initializare
void init(void)
{
	// initialize vector arrays
	Vector3D::arr = new float[3];
	Vector4D::arr = new float[4];

	// initializam camera principala
	camera = new Camera();
	camera->type=CameraTypeFREECAM;
	camera->SetPosition(Vector3D(0,10,20));

	//initializam camera secundara
	cameraSide = new Camera();
	cameraSide->SetPosition(Vector3D(0,40,33));
	cameraSide->RotateX(0.94);
	cameraSide->type=CameraTypeFIXED;

	//numarul de obiecte
	objectCount = 35;
	// initializam vectorii de obiecte
	objects = new Object3D*[objectCount];
	collidableObjects = new Object3D*[objectCount];
	lights = new Light*[objectCount];
	
	//Pentru numararea obiectelor
	objectCount=0;
	lightCount=0;
	collidableObjectCount=0;

	/***********PLANUL DE JOC****************/
	// initializam un plan de latura 5.0f
	ground = new Plane(20.4f);
	// culoare
	ground->SetColor(new Vector3D(0.8,0,0.0));
	// setam o grila de 5
	ground->SetLevelOfDetail(2);
	// sub nivelul obiectelor
	ground->SetPosition(new Vector3D(0,0,0));
	// si wireframe
	ground->Wireframe = false;

	/********MARGINILE TERENULUI DE JOC********/
	//Cream marginile terenului jocului
	createTrack();

	/*********STALPI DE LUMINA****************/
	LightPole *lightPole;
	//Stalp 1
	lightPole=new LightPole(10);
	lightPole->SetColor(new Vector3D(0.4,0.4,0));
	lightPole->setDiffuseColor(Vector4D(0.4,0.4,0,1));
	lightPole->SetScale(new Vector3D(0.5,0.5,0.5));
	lightPole->setLightDirection(Vector3D(-0.5,-1,0));
	lightPole->SetPosition(new Vector3D(-16,0,0));
	lightPole->setBoundingBoxMargin(0.01,6,0.01,-0.01,-6,-0.01);
	lightPole->CollisionEnabled=false;
	objects[objectCount++]=lightPole;
	lights[lightCount++]=lightPole->getLight();
	
	//Stalp 2
	lightPole=new LightPole(6);
	lightPole->SetColor(new Vector3D(0.4,0.7,0));
	lightPole->setDiffuseColor(Vector4D(0.4,0.7,0,1));
	lightPole->SetScale(new Vector3D(0.5,0.5,0.5));
	lightPole->setLightDirection(Vector3D(-0.5,-1,0.5));
	lightPole->SetPosition(new Vector3D(10,0,-8));
	lightPole->setBoundingBoxMargin(0.01,6,0.01,-0.01,-6,-0.01);
	lightPole->CollisionEnabled=false;
	objects[objectCount++]=lightPole;
	lights[lightCount++]=lightPole->getLight();

	//Stalp 3
	lightPole=new LightPole(12);
	lightPole->SetColor(new Vector3D(0,0.4,0.4));
	lightPole->setDiffuseColor(Vector4D(0,0.4,0.4,1));
	lightPole->SetScale(new Vector3D(0.5,0.5,0.5));
	lightPole->setLightDirection(Vector3D(0.5,-1.3,0.3));
	lightPole->SetPosition(new Vector3D(16,0,16));
	lightPole->setBoundingBoxMargin(0.01,6,0.01,-0.01,-6,-0.01);
	lightPole->CollisionEnabled=false;
	objects[objectCount++]=lightPole;
	lights[lightCount++]=lightPole->getLight();

	/*************OBSTACOLE*************/
	Object3D *obstacol;

	//Obstacol 1 - Sfera portocalie - sus 
	obstacol=new Object3D(Sphere);
	obstacol->setDiffuseColor(Vector4D(0.5,0.2,0,1));
	obstacol->SetColor(new Vector3D(0.5,0.2,0));
	obstacol->SetScale(new Vector3D(0.5,0.5,0.5));
	obstacol->SetPosition(new Vector3D(-4,1,-19));
	obstacol->setBoundingBoxMargin(0.5,0.5,0.5,-0.5,-0.5,-0.5);
	objects[objectCount++]=obstacol;

	//Obstacol 2 - Paralelipiped mov - dreapta 
	obstacol=new Object3D(Cube);
	obstacol->setDiffuseColor(Vector4D(0.4,0.1,0.4,1));
	obstacol->SetColor(new Vector3D(0.4,0.1,0.4));
	obstacol->SetScale(new Vector3D(1,1.6,1));
	obstacol->SetPosition(new Vector3D(16.65,0.5,2));
	obstacol->setBoundingBoxMargin(0.5,0.8,0.5,-0.5,-0.8,-0.5);
	objects[objectCount++]=obstacol;

	//Obstacol 3 - Romb Turcuaz - jos 
	obstacol=new Object3D(Cube);
	obstacol->setDiffuseColor(Vector4D(0,0.6,0.4,1));
	obstacol->SetColor(new Vector3D(0,0.5,0.4));
	obstacol->SetScale(new Vector3D(1,1,1));
	obstacol->SetRotation(new Vector3D(45,45,0));
	obstacol->SetPosition(new Vector3D(12,1,17));
	obstacol->setBoundingBoxMargin(0.7,0.7,0.7,-0.7,-0.7,-0.7);
	rotatingObject=objectCount;
	objects[objectCount++]=obstacol;

	//Obstacol 4 - Cub galben - jos 
	obstacol=new Object3D(Cube);
	obstacol->setDiffuseColor(Vector4D(0.5,0.5,0,0.8));
	obstacol->SetColor(new Vector3D(0.5,0.5,0));
	obstacol->SetScale(new Vector3D(1,1.6,1));
	obstacol->SetPosition(new Vector3D(6,0.5,19));
	obstacol->setBoundingBoxMargin(0.5,0.5,0.5,-0.5,-0.5,-0.5);
	objects[objectCount++]=obstacol;

	//Obstacol 5 - Torus Verde - jos 
	obstacol=new Object3D(Torus);
	obstacol->setDiffuseColor(Vector4D(0,0.5,0,1));
	obstacol->SetColor(new Vector3D(0,0.5,0));
	obstacol->SetScale(new Vector3D(0.4,0.4,0.4));
	obstacol->SetPosition(new Vector3D(-10,0,19.5));
	obstacol->setBoundingBoxMargin(0.5,0.5,0.4,-0.5,-0.4,-0.5);
	objects[objectCount++]=obstacol;

	//Obstacol 6 - Sfera portocalie - jos 
	obstacol=new Object3D(Sphere);
	obstacol->setDiffuseColor(Vector4D(0.8,0.2,0,0.6));
	obstacol->SetColor(new Vector3D(0.5,0.2,0));
	obstacol->SetScale(new Vector3D(0.5,0.5,0.5));
	obstacol->SetPosition(new Vector3D(-5,1,16.8));
	obstacol->setBoundingBoxMargin(0.5,0.5,0.5,-0.5,-0.5,-0.5);
	translatingObject=objectCount;
	objects[objectCount++]=obstacol;

	//Obstacol 7 - Cilindru rosu - stanga 
	obstacol=new Object3D(Cylinder);
	obstacol->setDiffuseColor(Vector4D(0.8,0,0.1,0.6));
	obstacol->SetColor(new Vector3D(0.8,0,0.1));
	obstacol->SetScale(new Vector3D(0.3,0.3,4));
	obstacol->SetRotation(new Vector3D(90,0,0));
	obstacol->SetPosition(new Vector3D(-19.5,1,7));
	obstacol->setBoundingBoxMargin(0.3,4,0.3,-0.3,-4,-0.3);
	objects[objectCount++]=obstacol;

	//Obstacol 8 - Con albastru - stanga 
	obstacol=new Object3D(Cone);
	obstacol->setDiffuseColor(Vector4D(0,0,0.6,1));
	obstacol->SetColor(new Vector3D(0.8,0,0.1));
	obstacol->SetScale(new Vector3D(0.3,0.3,2));
	obstacol->SetRotation(new Vector3D(-90,0,0));
	obstacol->SetPosition(new Vector3D(-18.5,0,-10));
	obstacol->setBoundingBoxMargin(0.3,2,0.3,-0.3,0,-0.3);
	objects[objectCount++]=obstacol;
	
	

	/**************JUCATOR**************/
	player=new Player();
	objects[objectCount++]=player->car;
	player->car->otherObjects=objects;
	player->car->otherObjectsCount=objectCount;
	player->camera=camera;
	player->cameraType=PCTFreeCam;




	/*************LUMINI****************/

	//Lumina ambientala
	lights[lightCount++]=new Light();
	lights[lightCount-1]->setDiffuseColor(Vector4D(1,0,1,1));
	lights[lightCount-1]->SetPosition(new Vector3D(0,20,0));
	



	// pregatim o scena noua in opengl
	glClearColor(0.0, 0.0, 0.0, 0.0);	// stergem tot
	glEnable(GL_DEPTH_TEST);			// activam verificarea distantei fata de camera (a adancimii)
	glShadeModel(GL_SMOOTH);			// mod de desenare SMOOTH
	glEnable(GL_LIGHTING);				// activam iluminarea
	glEnable(GL_NORMALIZE);				// activam normalizarea normalelor
	glLightModelfv(GL_LIGHT_MODEL_AMBIENT,(Vector4D(1,1,1,1)).Array());
	glEnable(GL_ALPHA_TEST);
}
Ejemplo n.º 9
0
void PTracker::run()
{
	IdGenerator idGenerator(0);
	frameCount = 0;
	while(true)
	{
		SubFrame subResult = receive(subtractorBuffer);
		ClasifierFrame detectionResult = receive(classifierBuffer);

		bool buffersFull = shiftBuffers(subResult, detectionResult);
		if(!buffersFull)
			continue;
		
		frameCount++;
#if PROCESS

#pragma region setting data for time t
		auto detections = detectionBuffer[1];
		auto currentFrame = frameBuffer[1];
		auto currentGrayFrame = grayFrameBuffer[1];
		auto prevFrame = frameBuffer[0];
		auto currentForeground = foregroundBuffer[1];			
#pragma endregion 

#pragma region init tracks from first detections
		if(tracks.size() == 0 && detections.size() > 0)
		{
			tracks.clear();
			tracks.reserve(detections.size());
			for_each(begin(detections), end(detections), [&](detection& d){
				createTrack(d, idGenerator, currentGrayFrame);
			});
			continue;
		}
#pragma endregion

#pragma region predict track positions for time t
		
		auto lkoutput = currentFrame.clone();		
			deleteExitedTracks();
		beginTracking();
		for(auto it = begin(tracks); it != end(tracks); it++)		
			registerForTracking(*it);			
				
		performTracking();

		for(auto it = begin(tracks); it != end(tracks); it++)
		{			
			Rect kanadePrediction, kalmanPrediction;
			bool lucasSuccess = getMedianFlowPrediction(*it, kanadePrediction);
			bool kalmanSuccess = getKalmanPrediction(*it, kalmanPrediction);
			
			float minDist = 999999;
			auto finalPrediction = mergePredictions(lucasSuccess, kalmanSuccess, *it, kanadePrediction, kalmanPrediction, grayFrameBuffer, minDist);		
			it->assign(finalPrediction);		
			it->predictionDist = minDist;
		}			

#pragma endregion

		std::map<int, trackMatch> trMatches; 
		std::map<int, detectionMatch> detMatches;	

		
		matcher->begin();
		secMatcher->begin();
		for_each(begin(tracks), end(tracks), [&](track& tr){

			auto dit = detections.begin();
			auto dend = detections.end();
			for(;dit != dend; ++dit)
			{
				float score = matcher->match(tr, *dit, currentGrayFrame);
				if(score < 0)
					continue;

				float dist = secMatcher->match(tr, *dit, currentGrayFrame);
				if(dist > secMatcher->goodMaxDist)
				{					
					continue;
				}

				trackMatch trMatch = {dit->id, score};
				detectionMatch dMatch = {tr.id, score};

				if(detMatches.find(dit->id) == detMatches.end())
				{
					trMatches[tr.id] = trMatch;
					detMatches[dit->id] = dMatch;

				}else if(detMatches[dit->id].score < score)
				{
					auto exmatch = detMatches[dit->id];					
					trMatches.erase(exmatch.trackId);

					trMatches[tr.id] = trMatch;
					detMatches[dit->id] = dMatch;
				}								
			}							
		});			

#pragma region update track models and kalman
		for_each(begin(tracks), end(tracks), [&](track& tr){
			if(trMatches.find(tr.id) != trMatches.end())//matched detection with track
			{
				auto m = trMatches[tr.id];
				matcher->inferModel(tr, detections[m.detectionId], currentGrayFrame);
				secMatcher->inferModel(tr, detections[m.detectionId], currentGrayFrame);
				validators[tr.id].tick(true);

				correctKalman(tr);					
			}else
			{//detection not found for track
				float max = secMatcher->maxSimilarityDist;
				float dist = tr.predictionDist;
				if(dist < max) 
					validators[tr.id].tick(true);
				else
					validators[tr.id].tick(false);

				forwardKalman(tr);
			}
		});
#pragma endregion

#pragma region init new tracks from unmatched detections
		for_each(begin(detections), end(detections), [&](detection& mockdet){
			auto it = detMatches.find(mockdet.id);
			if(it == detMatches.end()){				
				auto inited = createTrack(mockdet, idGenerator, currentGrayFrame);
				trackMatch m = {mockdet.id, 1};
				trMatches[inited.id] = m;					
			}
		});
#pragma endregion 

#pragma region drawing_results

		if(debugPrint)
		{
			printf("frame %d========\n", frameCount);
			for(auto it = begin(tracks); it != end(tracks); it++)
			{
				if(trMatches.find(it->id) != trMatches.end())
					printf("track %d : detection %d\n", it->id, trMatches[it->id].detectionId);
			}
			cv::waitKey();
		}		

		auto fclone = currentFrame.clone();								
		DrawExtensions::drawDetections(detections, fclone);			

		DrawExtensions::drawTracks(tracks, fclone, Scalar(255,0,0));

		for_each(begin(tracks), end(tracks), [&](track& tr){
			Draw::rect(tr.model.kalmanRect, fclone, Scalar(0,0,255));
		});

		//imshow("xxx", currentForeground);
		//cv::waitKey(50);

		std::stringstream str;
		str << carCount;			
		Draw::text(str.str(), Point(10,20), fclone, Scalar(255,255,0));

		imshow("kalman", fclone);
		
		fclone.release();
		lkoutput.release();
#pragma endregion

#endif

		char key;
		key = cv::waitKey(1.);
		if(key == 's')
			debugPrint = true;
		else if(key == 'f')
			debugPrint = false;
	
		send(syncBuffer,1);			
	}
}