Ejemplo n.º 1
0
Int32 AlgLink_ScdalgProcess(AlgLink_ScdObj *pScdAlgLinkObj, UInt32 chId, AlgLink_ScdResult * scdResultBuff)
{
    SCD_Status      chanStatus; 
    SCD_Result      scdResult;
    UInt32          chanID;
    SCD_chPrm       chanParam;
    AlgLink_ScdchPrm * chPrm;
    UInt32         blkIdx;

    /* Activate the Algorithm */
    DSKT2_activateAlg(gScratchId, (IALG_Handle)pScdAlgLinkObj->algHndl);

    chanID = pScdAlgLinkObj->chParams[chId].chId;
    chPrm = &(pScdAlgLinkObj->chParams[chId]);

    chanParam.chId	                = chPrm->chId;
    chanParam.mode	                = (SCD_Mode)chPrm->mode;
    chanParam.width	              = chPrm->width;
    chanParam.height               = chPrm->height;
    chanParam.stride               = chPrm->stride;
    chanParam.curFrame             = chPrm->curFrame;
    chanParam.frmSensitivity       = (SCD_Sensitivity)chPrm->frmSensitivity;
    chanParam.frmIgnoreLightsON    = chPrm->frmIgnoreLightsON;
    chanParam.frmIgnoreLightsOFF   = chPrm->frmIgnoreLightsOFF;
    chanParam.frmEdgeThreshold     = chPrm->frmEdgeThreshold;

    if(chPrm->chBlkConfigUpdate == TRUE)
    {
        chanParam.blkConfig = (SCD_blkChngConfig *) chPrm->blkConfig;
    }
    else
    {
        chanParam.blkConfig = NULL;
    }
    chanStatus = SCD_TI_setPrms(pScdAlgLinkObj->algHndl, &chanParam, chanID);

    if(chanStatus != SCD_NO_ERROR)
    {
#ifdef SYSTEM_DEBUG_SCD
        Vps_printf(" %d: SCD    : ERROR: Alg Set Params (chanID = %d) - 0x%08X !!!\n",
                  Utils_getCurTimeInMsec(), chanID, chanStatus);
#endif
        /* Deactivate algorithm */
        DSKT2_deactivateAlg(gScratchId, (IALG_Handle)pScdAlgLinkObj->algHndl);
        return FVID2_EFAIL;
    }


    scdResult.frmResult = SCD_DETECTOR_NO_CHANGE;
    scdResult.blkResult = (SCD_blkChngMeta *)(scdResultBuff->blkResult);
    
    chanStatus = SCD_TI_process(pScdAlgLinkObj->algHndl, chanID, &scdResult);


    /* Deactivate algorithm */
    DSKT2_deactivateAlg(gScratchId, (IALG_Handle)pScdAlgLinkObj->algHndl);

    if(chanStatus != SCD_NO_ERROR)
    {
#ifdef SYSTEM_DEBUG_SCD
        Vps_printf(" %d: SCD    : ERROR: Alg Process (chanID = %d) !!!\n",
                  Utils_getCurTimeInMsec(), chanID );
#endif

        return FVID2_EFAIL;
    }

    scdResultBuff->frmResult = (AlgLink_ScdOutput) scdResult.frmResult;
    scdResultBuff->chId = chanID;

//    if(pScdAlgLinkObj->createArgs.chDefaultParams[chId].mode & SCD_DETECTMODE_MONITOR_BLOCKS)
    if(pScdAlgLinkObj->chParams[chId].mode & SCD_DETECTMODE_MONITOR_BLOCKS)
    {
        UInt32 numBlkChg;
        UInt32 monitoredBlk;
        UInt32 numHorzBlks, numVertBlks, numBlksInFrame, blkHeight;
        AlgLink_ScdResult *pChResult = scdResultBuff;    	
        pChResult->frmResult = ALG_LINK_SCD_DETECTOR_CHANGE;
        pChResult->chId   = chanID;

        monitoredBlk = 0;
        numBlkChg = 0;
        numHorzBlks     = ((pScdAlgLinkObj->chParams[chId].width + 0x1F ) & (~0x1F)) / 32;  /* Rounding to make divisible by 32 */
        if((pScdAlgLinkObj->chParams[chId].height%ALG_LINK_SCD_BLK_HEIGHT_MIN) == 0)/* For Block height is divisible by 10 */
           blkHeight = ALG_LINK_SCD_BLK_HEIGHT_MIN;
        else   /* For Block height is divisible by 12 */
           blkHeight = ALG_LINK_SCD_BLK_HEIGHT;
        numVertBlks    = pScdAlgLinkObj->chParams[chId].height / blkHeight;

        numBlksInFrame = numHorzBlks * numVertBlks;


        for(blkIdx = 0; blkIdx < numBlksInFrame; blkIdx++)
        {
            if(pScdAlgLinkObj->chParams[chId].blkConfig[blkIdx].monitored == 1)
            {
                monitoredBlk++;
                if(scdResultBuff->blkResult[blkIdx].numPixelsChanged > MOTION_DETECTION_SENSITIVITY(ALG_LINK_SCD_BLK_WIDTH, blkHeight))
                    numBlkChg++;
            }
        }
        if((monitoredBlk > 0) && (numBlkChg > (NUM_BLOCK_MOTION_DETECTION_THRESOLD(monitoredBlk))))
        {
#ifdef SYSTEM_DEBUG_SCD_RT
            Vps_printf(" %d: SCD    : Motion Detected (chanID = %d) !!!\n",
                  Utils_getCurTimeInMsec(), chanID );
#endif
            System_linkControl(SYSTEM_LINK_ID_HOST, VSYS_EVENT_MOTION_DETECT, pChResult, sizeof(AlgLink_ScdResult), FALSE);
        
        }
         
    }
    if(scdResult.frmResult == SCD_DETECTOR_CHANGE)
    {
        AlgLink_ScdChStatus *pChStatus = &pScdAlgLinkObj->scdChStat[chanID];    	
        pChStatus->size   = sizeof(AlgLink_ScdChStatus);
        pChStatus->frmResult = (UInt32) ALG_LINK_SCD_DETECTOR_CHANGE;
        pChStatus->chId   = chanID;
#if 0 
        /* Will be used post GA */
        AlgLink_ScdprocessSCDmetadata(scdResultBuff,
                                      &(pScdAlgLinkObj->chParams[chId]),
                                      pChStatus);
#endif
#ifdef SYSTEM_DEBUG_SCD_RT
        Vps_printf(" %d: SCD    : Tamper Detected (chanID = %d) !!!\n",
                  Utils_getCurTimeInMsec(), chanID );
#endif

        System_linkControl(SYSTEM_LINK_ID_HOST, VSYS_EVENT_TAMPER_DETECT, pChStatus, sizeof(AlgLink_ScdChStatus), FALSE);
    }


    return FVID2_SOK;
}
Ejemplo n.º 2
0
Int32 AlgLink_ScdalgProcess(AlgLink_ScdObj *pScdAlgLinkObj, UInt32 chId, AlgLink_ScdResult * scdResultBuff)
{
    SCD_Status      chanStatus;
    SCD_Result      scdResult;
    UInt32          chanID;
    SCD_chPrm       chanParam;
    AlgLink_ScdchPrm * chPrm;
    AlgLink_ScdChObj * chObj;
    UInt32         blkIdx;
	//System_FrameInfo *pInFrameInfo;

    /* Activate the Algorithm */
    DSKT2_activateAlg(gScratchId, (IALG_Handle)pScdAlgLinkObj->algHndl);

    chanID = pScdAlgLinkObj->chParams[chId].chId;
    chPrm = &(pScdAlgLinkObj->chParams[chId]);
    chObj = &(pScdAlgLinkObj->chObj[chId]);

    chanParam.chId	                = chPrm->chId;
    chanParam.mode	                = (SCD_Mode)chPrm->mode;
    chanParam.width	              = chPrm->width;
    chanParam.height               = chPrm->height;
    chanParam.stride               = chPrm->stride;
    chanParam.curFrame             = chPrm->curFrame;
    chanParam.frmSensitivity       = (SCD_Sensitivity)chPrm->frmSensitivity;
    chanParam.frmIgnoreLightsON    = chPrm->frmIgnoreLightsON;
    chanParam.frmIgnoreLightsOFF   = chPrm->frmIgnoreLightsOFF;
    chanParam.frmEdgeThreshold     = chPrm->frmEdgeThreshold;

    if(chPrm->chBlkConfigUpdate == TRUE)
    {
        chanParam.blkConfig = (SCD_blkChngConfig *) chPrm->blkConfig;
    }
    else
    {
        chanParam.blkConfig = NULL;
    }
    chanStatus = SCD_TI_setPrms(pScdAlgLinkObj->algHndl, &chanParam, chanID);

    if(chanStatus != SCD_NO_ERROR)
    {
#ifdef SYSTEM_DEBUG_SCD
        Vps_printf(" %d: SCD    : ERROR: Alg Set Params (chanID = %d) - 0x%08X !!!\n",
                  Utils_getCurTimeInMsec(), chanID, chanStatus);
#endif
        /* Deactivate algorithm */
        DSKT2_deactivateAlg(gScratchId, (IALG_Handle)pScdAlgLinkObj->algHndl);
        return FVID2_EFAIL;
    }


    scdResult.frmResult = SCD_DETECTOR_NO_TAMPER;
    scdResult.blkResult = (SCD_blkChngMeta *)(scdResultBuff->blkResult);

    chanStatus = SCD_TI_process(pScdAlgLinkObj->algHndl, chanID, &scdResult);
	chanStatus = SCD_NO_ERROR;

    /* Deactivate algorithm */
    DSKT2_deactivateAlg(gScratchId, (IALG_Handle)pScdAlgLinkObj->algHndl);

    if(chanStatus != SCD_NO_ERROR)
    {
#ifdef SYSTEM_DEBUG_SCD
        Vps_printf(" %d: SCD    : ERROR: Alg Process (chanID = %d) !!!\n",
                  Utils_getCurTimeInMsec(), chanID );
#endif

        return FVID2_EFAIL;
    }

    scdResultBuff->frmResult = (AlgLink_ScdOutput) scdResult.frmResult;
    scdResultBuff->chId = chanID;

//    if(pScdAlgLinkObj->createArgs.chDefaultParams[chId].mode & SCD_DETECTMODE_MONITOR_BLOCKS)

    /* Motion detect event notification. */
    if(pScdAlgLinkObj->chParams[chId].mode & SCD_DETECTMODE_MONITOR_BLOCKS)
    {
        UInt32 numBlkChg;
        UInt32 monitoredBlk;
        UInt32 numHorzBlks, numVertBlks, numBlksInFrame, blkHeight;

        monitoredBlk = 0;
        numBlkChg = 0;
        numHorzBlks     = ((pScdAlgLinkObj->chParams[chId].width + 0x1F ) & (~0x1F)) / 32;  /* Rounding to make divisible by 32 */
        if((pScdAlgLinkObj->chParams[chId].height%ALG_LINK_SCD_BLK_HEIGHT_MIN) == 0)/* For Block height is divisible by 10 */
           blkHeight = ALG_LINK_SCD_BLK_HEIGHT_MIN;
        else   /* For Block height is divisible by 12 */
           blkHeight = ALG_LINK_SCD_BLK_HEIGHT;
        numVertBlks    = pScdAlgLinkObj->chParams[chId].height / blkHeight;

        numBlksInFrame = numHorzBlks * numVertBlks;

        /* Logic  to see how many blocks of total enabled blocks experienced change.
         * For each block, algorithm returns no. of pixels changed in the current
         * frame. This is compared against thresold determined using SCD sensitivity .
         * if changed pixels are more than the calculated thresold, block is marked as changed
         * i.e. motion is detected in the block.
         * Minimum value of thresold is 20% and then it is incrmented by 10% for
         * each sensitivity level change. Thresold can vary from 20% - 100%
         * At max sensitivity, thresold would be 20%. That means if 20% pixels
         * are changed block is marked as changed.
         * At minimu sensitivity, thresold would be 100%. That means if 100% pixels
         * are changed block is marked as changed */

        for(blkIdx = 0; blkIdx < numBlksInFrame; blkIdx++)
        {
            SCD_blkChngConfig * blockConfig;

            blockConfig = &pScdAlgLinkObj->chParams[chId].blkConfig[blkIdx];
            scdResultBuff->blkConfig[blkIdx].monitored   = blockConfig->monitored;
            scdResultBuff->blkConfig[blkIdx].sensitivity = blockConfig->sensitivity;
            if(blockConfig->monitored == 1)
            {
                UInt32 threshold;

                monitoredBlk++;
                threshold = MOTION_DETECTION_SENSITIVITY(ALG_LINK_SCD_BLK_WIDTH, blkHeight) +
                                  (MOTION_DETECTION_SENSITIVITY_STEP * (SCD_SENSITIVITY_MAX - blockConfig->sensitivity));
#if 0
		 if(scdResultBuff->blkResult[blkIdx].numPixelsChanged > 0)
	  	 Vps_printf("===========blkIdx:%d,numPixelsChanged:%d\n",blkIdx,scdResultBuff->blkResult[blkIdx].numPixelsChanged);
#endif
                if(scdResultBuff->blkResult[blkIdx].numPixelsChanged > threshold)
                {
                    numBlkChg++;
                }
            }
        }

        /* Logic  to notify A8-host about motion detection.
         * Currently, if atleast 1 block is detected as changed A8 is notified.
         * User can use commented logic to chnage this behavior. */
        /* if((monitoredBlk > 0) && (numBlkChg > (NUM_BLOCK_MOTION_DETECTION_THRESOLD(monitoredBlk)))) */

        if(pScdAlgLinkObj->createArgs.enableMotionNotify)
        {
           if((monitoredBlk > 0) && (numBlkChg > 0))
           {
#ifdef SYSTEM_DEBUG_SCD_RT
               Vps_printf(" %d: SCD    : Motion Detected (chanID = %d),  !!!\n",
                      Utils_getCurTimeInMsec(), chanID );
#endif
               System_linkControl(SYSTEM_LINK_ID_HOST, VSYS_EVENT_MOTION_DETECT, scdResultBuff, sizeof(AlgLink_ScdResult), TRUE);

           }
        }

    }

    chObj->scdChStat = ALG_LINK_SCD_DETECTOR_UNAVAILABLE;

    if(scdResult.frmResult == SCD_DETECTOR_NO_TAMPER)
        chObj->scdChStat = ALG_LINK_SCD_DETECTOR_NO_CHANGE;
    else if(scdResult.frmResult == SCD_DETECTOR_TAMPER)
        chObj->scdChStat = ALG_LINK_SCD_DETECTOR_CHANGE;


    if(pScdAlgLinkObj->createArgs.enableTamperNotify)
    {

    /* Tamper detect event notification. */
        if(scdResult.frmResult == SCD_DETECTOR_TAMPER)
        {
            AlgLink_ScdChStatus pChStatus;

            pChStatus.frmResult = (UInt32) ALG_LINK_SCD_DETECTOR_CHANGE;
            pChStatus.chId      = chObj->chId;


#ifdef SYSTEM_DEBUG_SCD_RT
            Vps_printf(" %d: SCD    : Tamper Detected (chanID = %d) !!!\n",
                      Utils_getCurTimeInMsec(), chanID );
#endif

            System_linkControl(SYSTEM_LINK_ID_HOST, VSYS_EVENT_TAMPER_DETECT, &pChStatus, sizeof(AlgLink_ScdChStatus), TRUE);
        }
    }

    return FVID2_SOK;
}