private Math::Matrix <double> CalculateInputMatrix(IList <string> frameImageFilePaths) { Math::Matrix <double> X = new DenseMatrix(frameImageFilePaths.Count, featureExtractor.Length); StructuringElementEx kernel = new StructuringElementEx(3, 3, 1, 1, CV_ELEMENT_SHAPE.CV_SHAPE_ELLIPSE); ParallelOptions options = new ParallelOptions(); options.MaxDegreeOfParallelism = 1; Parallel.ForEach(Enumerable.Range(0, frameImageFilePaths.Count), options, i => { Math::Vector <double> featureVector = featureExtractor.ExtractFeatures(new Image <Gray, Byte>(frameImageFilePaths[i])); X.SetSubMatrix(i, 1, 0, featureExtractor.Length, featureVector.ToRowMatrix()); }); Console.Write(X.Row(1)); return(X); }
public Math::Vector <double> ExtractFeatures(Image <Gray, Byte> frame) { Math::Vector <double> result = new DenseVector(Length); Image <Gray, Byte> grayFrame = frame.Resize(frameWidth, frameHeight, INTER.CV_INTER_AREA); Image <Gray, Byte> foregroundMask = grayFrame.AbsDiff(background).ThresholdBinary(new Gray(40), new Gray(255)) - grayFrame.ThresholdBinary(new Gray(200), new Gray(255)); CvInvoke.cvDilate(foregroundMask, foregroundMask, structuringElement, 1); CvInvoke.cvErode(foregroundMask, foregroundMask, structuringElement, 2); CvInvoke.cvDilate(foregroundMask, foregroundMask, structuringElement, 1); //Image<Gray, byte> outline = foregroundMask - foregroundMask.Erode(1); //Image<Gray, byte> edges = grayFrame.Canny(80, 150); //Image<Gray, byte> foregroundEdges = edges.Min(foregroundMask.Dilate(1)); //outline.Save(@"D:\! Egyetem\! RWTH\Semester 2\Seminar CV\Datasets\UCSD\derived images\outlines\" + i + ".png"); //foregroundEdges.Save(@"D:\! Egyetem\! RWTH\Semester 2\Seminar CV\Datasets\UCSD\derived images\edges\" + i + ".png"); //foregroundMask.Save(@"D:\! Egyetem\! RWTH\Semester 2\Seminar CV\Datasets\UCSD\derived images\masks\" + i + ".png"); //i++; IList <Image <Gray, Byte> > frameCells = ImageSplitter.SplitImage(grayFrame, N, M); IList <Image <Gray, Byte> > foregroundMaskCells = ImageSplitter.SplitImage(foregroundMask, N, M); int cellHeight = frame.Height / N; int cellWidth = frame.Width / M; for (int cellId = 0; cellId < frameCells.Count; ++cellId) { int offsetX = (cellId % M) * cellWidth; int offsetY = (cellId / M) * cellHeight; Math::Vector <double> featureVector = cellFeatureExtractor.ExtractFeatures( frameCells[cellId], foregroundMaskCells[cellId], perspectiveCorrector.GetScaleFunction(offsetX, offsetY, frameHeight)); result.SetSubVector(featureVector.Count * cellId, featureVector.Count, featureVector); } return(result); }