unsigned int CFrameJSegmentor::GetSegmentNum(const CFrame & frame)
{
         if( frame.Id() != m_FrameId )
            DetectSemgment(frame);

         return m_SegmentNum;
}
void CFrameJSegmentor::DetectSemgment(const CFrame & frame)
{
        if( m_RegionMap )
            m_RegionMap->Release();
        m_SegmentNum = m_SegmentDetector->Segment(*frame.GetImage(), &m_RegionMap);
        m_FrameId = frame.Id();
}
	HRESULT CSabOnlineSubshotDetectorImp::DetectNewSubshot(CFrame & frame)
	{
            m_FrameId = frame.Id();

		    if ( m_SubshotIdx < (m_SubshotList.Size()-1) && !m_IsInSubshot )
		    {
			     m_SubshotIdx++;

			     m_BgnFrameId = m_SubshotList[m_SubshotIdx].BeginFrameId();
			     m_EndFrameId = m_SubshotList[m_SubshotIdx].EndFrameId();
		   }

		   if ( m_FrameId <= m_BgnFrameId )
		   {
                // We have get the next sub shot, but frame is not arrived the bgn frame of the sub shot
		        // Example: sub shot(bgnFrameId, endFrameId): 1 (1, 10)  2(15, 20)
		        // If we arrive frame 11, we have entered the subshot 2, but we need to set the flag
			    m_IsInSubshot = true;
		   }

		   if ( m_FrameId == m_BgnFrameId )
           {
                m_SubshotList[m_SubshotIdx].BeginTime(frame.BeginTime());
                m_IsSubshotStart = true;
           }
		
           m_KeyframeExtractor->OnNewFrame(frame, m_IsSubshotStart);

		   //we get a new sub shot
		   if ( m_FrameId == m_EndFrameId )
		   {
			    m_IsInSubshot = false;
                m_IsSubshotStart = false;
			    m_SubshotList[m_SubshotIdx].EndTime(frame.EndTime());

                //extract the key frame for current sub shot
                //add the last frame
                m_KeyframeExtractor->OnNewFrame(frame, true);
                CFrameList & keyframeList = m_KeyframeExtractor->OnNewSegment(m_SubshotList[m_SubshotIdx]);
				int size = keyframeList.Size();
					
                for( int i = 0; i < size; ++i )
					  m_SubshotList[m_SubshotIdx].AddKeyframe(keyframeList[i]);

			    return S_OK;
		   }
		   
           return S_FALSE;
	}