Мне интересно, может ли кто-нибудь объяснить метод, который добавляет объекты с одинаковым значением атрибута в отдельные списки.
В этом случае список кандидатов не может содержать кандидатов с одинаковым номером кадра.
Я ищу способ реализовать это в методе Add () для CandidateList.
Как этого добиться?
public class CandidateList
{
public CandidateList()
{
_Candidates1 = new List<Candidate>();
_Candidates2 = new List<Candidate>();
_Candidates3 = new List<Candidate>();
_Candidates4 = new List<Candidate>();
}
public void Add(Candidate candidate)
{
// Check candidate frame number
// How to decide which list candidate should be added to?
// If candidate.frameNumber matches an element in Candidates1[candidate.framenumber]
// add this candidate to Candidates2, and so on..
}
}
public class Candidate
{
//Attributes shown in constructor.
public Candidate(VectorOfPoint contour, int frameNumber, double contourSize, Point location)
{
Contour = contour;
FrameNumber = frameNumber;
ContourSize = contourSize;
Location = location;
Location_x = Location.X;
Location_y = Location.Y;
}
}
_vc = new VideoCapture(someURLorFilePath);
_candidateList = new CandidateList();
_vc.ImageGrabbed += ProcessFrame;
public void ProcessFrame(object sender, EventArgs e)
{
Mat _frame = new Mat();
// read frame.. + other operations to get desired data.
Mat _contourOutput = _frame.Clone();
VectorOfVectorOfPoint _contours = new VectorOfVectorOfPoint();
CvInvoke.FindContours(_contourOutput, _contours, new Mat(), RetrType.External, ChainApproxMethod.ChainApproxSimple);
// If there are any contours
if (_contours.Size > 0)
{
// Iterate through contours
for (var i = 0; i < _contours.Size; i++)
{
// Find contour area of each contour (VectorOfPoint)
double _contourArea = CvInvoke.ContourArea(_contours[i]);
// Find centre of contour
Moments M = CvInvoke.Moments(_contours[i]);
Point _contourCentre = new Point(Convert.ToInt16(M.M10 / M.M00), Convert.ToInt16(M.M01 / M.M00));
// Create a candidate based on frame number, contourSize and location
Candidate _candidate = new Candidate(_contours[i], _currentFrameNo, _contourArea, _contourCentre);
_candidateList.Add(_candidate)
}
}
_currentFrameNo ++
}