Untitled
unknown
plain_text
10 months ago
5.7 kB
13
Indexable
public NoiseSuppressionSmartSearch(DateTime dtStart, DateTime dtEnd, List<int> listCameraID, bool bArchieved) : base(dtStart, dtEnd, listCameraID, bArchieved)
{
}
protected override bool CollectSmartSearchFrames(int cameraId, string strVideoFilename)
{
string strFilename = Path.ChangeExtension(strVideoFilename, ".ctf");
try
{
bool bSmartFrameFound = false;
List<TriggerFileReader.TriggerFileRecord> triggerFileRecords = null;
TriggerFileReader tfr = new TriggerFileReader(strFilename, null);
triggerFileRecords = tfr.ReadFrames().ToList();
TriggerFileReader.TriggerFileHeaderNoiseMask triggerFileNoiseMask = tfr.ReadHeaderNoiseMask();
try
{
var frameIndicesSinceIFrame = new List<UInt32>();
var frameIndices = new List<UInt32>();
bool bKeepFrame = false;
for (UInt32 nCurrentFrame = 0; nCurrentFrame < triggerFileRecords.Count(); nCurrentFrame++)
{
TriggerFileReader.TriggerFileRecord tfrR = triggerFileRecords[(int)nCurrentFrame];
if (((eSampleType)tfrR.FrameType == eSampleType.CC_SAMPLETYPE_MPEG4_IFRAME)
|| ((eSampleType)tfrR.FrameType == eSampleType.CC_SAMPLETYPE_MPEG4AVC_IFRAME)
|| ((eSampleType)tfrR.FrameType == eSampleType.CC_SAMPLETYPE_MJPEG))
{
bKeepFrame = false;
frameIndicesSinceIFrame.Clear();
}
if (!bKeepFrame)
{
// if not keeping frames, save it so we can add all frames since the last IFrame to make results is playable
frameIndicesSinceIFrame.Add(nCurrentFrame);
if(!triggerFileNoiseMask.m_enabled)
{
bKeepFrame = true;
}
if (!bKeepFrame && tfrR.MotionDataWidth > 0 && tfrR.MotionDataHeight > 0) // we have motion
{
//// Build Collision Rectangles List, once per Search (do we need to do, once per file?)
//if (m_collision_list == null)
// BuildCollisionRectanglesList(tfrR.MotionDataWidth, tfrR.MotionDataHeight);
//each bit indicates motion or no motion on the motion grid
BitArray motion_bits = new System.Collections.BitArray(tfrR.MotionData);
BitArray noise_mask_bits = new System.Collections.BitArray(triggerFileNoiseMask.m_data);
//we are performing the A AND ~(B) to suppress motion bits that are also noise bits.
noise_mask_bits.Not();
motion_bits.And(noise_mask_bits);
foreach(Boolean val in motion_bits)
{
if (val)
{
try
{
bKeepFrame = true;
break;
}
catch (Exception ex)
{
System.Diagnostics.Trace.WriteLine("CollectSmartSearchFrames error/continue anyway " + Environment.NewLine + ex.ToString());
}
}
}
}
// start keeping frames until the next IFrame
if (bKeepFrame)
{
// add all frames since the last IFrame, which already includes the current frame.
frameIndices.AddRange(frameIndicesSinceIFrame);
frameIndicesSinceIFrame.Clear();
}
}
else if (bKeepFrame)
{
frameIndices.Add(nCurrentFrame);
}
}
if (frameIndices.Count() != 0)
{
m_nTotalFiles++;
m_nTotalFrames += (uint)frameIndices.Count;
bSmartFrameFound = true;
if (IsReturnAnObject)
{
// save the data into our return object
int number_of_frames = (int)frameIndices.Count;
SmartSearchResultsFileCMS ssfile = new SmartSearchResultsFileCMS(number_of_frames);
ssfile.FileName = strVideoFilename;
ssfile.FrameIndicies = frameIndices.ToArray();
ssfile.FrameCount = (uint)number_of_frames;
_retObject.AddFileData(ssfile);
}
else
{
// Write into file here
m_SmartSearchWriter.WriteSmartSearchData(strVideoFilename, (uint)frameIndices.Count, frameIndices.ToArray());
}
}
}
catch (Exception ex)
{
System.Diagnostics.Trace.WriteLine("CollectSmartSearchFrames error for file " + strFilename + " " + Environment.NewLine + ex.ToString());
}
return bSmartFrameFound;
}
catch (Exception ex)
{
System.Diagnostics.Trace.WriteLine("CollectSmartSearchFrames MAIN error for file " + strFilename + " " + Environment.NewLine + ex.ToString());
throw;
}
}Editor is loading...
Leave a Comment