public override void Process() { if (!FInput.LockForReading()) { return; } FInput.GetImage(FHsvImage); FInput.ReleaseForReading(); CvInvoke.cvInRangeS(FHsvImage.CvMat, new MCvScalar(Minimum.x * FMult, Minimum.y * FMult, Minimum.z * FMult), new MCvScalar(Maximum.x * FMult, Maximum.y * FMult, Maximum.z * FMult), FBuffer.CvMat); if (PassOriginal) { FOutput.Image.SetImage(FInput.Image); CvInvoke.cvNot(FBuffer.CvMat, FBuffer.CvMat); CvInvoke.cvSet(FOutput.Image.CvMat, new MCvScalar(0.0), FBuffer.CvMat); FOutput.Send(); } else { FOutput.Send(FBuffer); } }
public override void Process() { //If we want to pull out an image in a specific format //then we must have a local instance of a CVImage initialised to that format //and use //FInput.Image.GetImage(TColorFormat.L8, FInputL8); //in that example, we expect to have a FInputL8 locally which has been intialised //with the correct size and colour format //Whenever you access the pixels directly of FInput //e.g. when using the .CvMat accessor //you must lock it for reading using if (!FInput.LockForReading()) //this { return; } CvInvoke.cvPyrDown(FInput.CvMat, FOutput.CvMat, FILTER_TYPE.CV_GAUSSIAN_5x5); FInput.ReleaseForReading(); //and this after you've finished with FImage if (FInput.ImageAttributes.ColourFormat == TColorFormat.RGB8) { PixelWiseAdd(); } FOutput.Send(); }
public override void Evaluate(int SpreadMax) { var update = CheckReset(); if (FInput.IsChanged && !FInput.IsAnyInvalid()) { foreach (var message in FInput) { if (!Keep.Contains(message)) { Keep.Add(message); update = true; } } } if (UpKeep()) { update = true; } if (update) { FOutput.FlushResult(Keep); } }
//called when data for any output pin is requested public override void Evaluate(int SpreadMax) { var update = CheckReset(); if (!FInput.IsAnyInvalid() && FInput.IsChanged) { foreach (var message in FInput) { if (!Keep.Contains(message)) { Keep.Add(message); update = true; } } } if (RemoveOldOrFlagged()) { update = true; } if (UpKeep(update)) { update = true; } }
public override void Evaluate(int SpreadMax) { SpreadMax = FInput.SliceCount; if (FInput.IsAnyInvalid()) { SpreadMax = 0; } for (int i = 0; i < SpreadMax; i++) { var agent = FInput[i]; if (FInitFirst[0]) { Type face = AllAgentFaces[FFace[0].Index]; agent.Init(face, FInitFirst[0]); } foreach (string pinName in FPins.Keys) { var pin = ((ISpread)FPins[pinName].RawIOObject); pin.Sync(); agent.Assign(pinName, pin[i]); } } FOutput.AssignFrom(FInput); }
public override void Process() { if (!FInput.LockForReading()) { return; } CvInvoke.cvCmpS(FInput.CvMat, Threshold, FOutput.CvMat, CMP_TYPE.CV_CMP_LT); FInput.ReleaseForReading(); FOutput.Send(); }
public override void Process() { if (!FInput.LockForReading()) //this { return; } CvInvoke.cvNot(FInput.CvMat, FOutput.CvMat); FInput.ReleaseForReading(); //and this after you've finished with FImage FOutput.Send(); }
public override void Process() { FChannelCount = ImageUtils.ChannelCount(FInput.ImageAttributes.ColourFormat); if (!FInput.LockForReading()) { return; } CvInvoke.cvAvgSdv(FInput.CvMat, ref FAverage, ref FStandardDeviation, IntPtr.Zero); FInput.ReleaseForReading(); }
public override void Process() { if (!FInput.LockForReading()) { return; } CvInvoke.cvErode(FInput.CvMat, FOutput.CvMat, IntPtr.Zero, FIterations); FInput.ReleaseForReading(); FOutput.Send(); }
public override void Process() { if (!FInput.LockForReading()) { return; } CvInvoke.cvAdaptiveThreshold(FInput.CvMat, FOutput.CvMat, FMaximum, FMethod, FType, (int)FBlockSize, FConstant); FInput.ReleaseForReading(); FOutput.Send(); }
public override void Process() { lock (this.FeaturesSet.Lock) { FInput.GetImage(FGrayScale); var gray = FGrayScale.GetImage() as Image <Gray, Byte>; this.FeaturesSet.KeyPoints = this.Detector.DetectKeyPointsRaw(gray, null); this.FeaturesSet.Descriptors = this.Detector.ComputeDescriptorsRaw(gray, null, this.FeaturesSet.KeyPoints); this.FeaturesSet.Allocated = true; this.FeaturesSet.OnUpdate(); } }
public override void Evaluate(int SpreadMax) { var update = CheckReset(); if (FInput.IsChanged && !FInput.IsAnyInvalid()) { Keep.AssignFrom(FInput); update = true; } if (UpKeep()) { update = true; } if (FHold.IsChanged) { update = true; } if (FHold[0] == HoldEnum.Index && FIndex.IsChanged) { update = true; } if (update) { switch (FHold[0]) { case HoldEnum.All: FOutput.SliceCount = 0; FOutput.AssignFrom(Keep); break; case HoldEnum.Index: if (Keep.Count == 0) { FOutput.SliceCount = 0; } else { FOutput.SliceCount = FIndex.SliceCount; for (int i = 0; i < FIndex.SliceCount; i++) { var index = VMath.Zmod(FIndex[i], Keep.Count); FOutput[i] = Keep[index]; } } break; } FOutput.Flush(); } }
public override void Process() { if (!Ready) { return; } if (FNeedsReset) { FNeedsReset = false; ResetMaps(); } if (FApply && TimestampRegister != null) { FInput.LockForReading(); try { ulong Frame; if (TimestampRegister.Lookup(FInput.Image.Timestamp, out Frame)) { if (!(WaitForTimestamp && Frame == LastFrameCaptured)) { LastFrameCaptured = Frame; FFramesDetected++; if (!WaitForTimestamp) { FApply = false; } if (ScanSet.Payload.Balanced) { bool positive = Frame % 2 == 0; FInput.GetImage(positive ? FPositive : FNegative); if (!positive && Frame / 2 == CurrentBalancedFrame) { ApplyBalanced(Frame / 2); } CurrentBalancedFrame = Frame / 2; } } } } finally { FInput.ReleaseForReading(); } ScanSet.Evaluate(); } }
public override void Process() { if (!FInput.LockForReading()) { return; } CvInvoke.cvCmpS(FInput.CvMat, Minimum, FImageGT.CvMat, CMP_TYPE.CV_CMP_GE); CvInvoke.cvCmpS(FInput.CvMat, Maximum, FImageLT.CvMat, CMP_TYPE.CV_CMP_LE); FInput.ReleaseForReading(); CvInvoke.cvAnd(FImageGT.CvMat, FImageLT.CvMat, FOutput.CvMat, IntPtr.Zero); FOutput.Send(); }
public override void Process() { FInput.LockForReading(); try { CvInvoke.cvConvertScale(FInput.CvMat, FOutput.CvMat, Scale, Offset); } finally { FInput.ReleaseForReading(); } FOutput.Send(); }
public override void Process() { FInput.LockForReading(); try { CvInvoke.cvSobel(FInput.CvMat, FOutput.CvMat, FXOrder, FYOrder, FAperture); } finally { FInput.ReleaseForReading(); } FOutput.Send(); }
void WriteTexture(Resource resource) { var texture = resource.Texture; CVImage image; if (FNeedsConversion) { FBuffer.LockForReading(); image = FBuffer.FrontImage; } else { FInput.LockForReading(); image = FInput.Image; } try { var imageAttributes = image.ImageAttributes; if (imageAttributes.Stride == texture.GetRowPitch()) { //write raw texture.WriteData(image.Data, imageAttributes.BytesPerFrame); } else { //write with pitch texture.WriteDataPitch(image.Data, (int)imageAttributes.BytesPerFrame, imageAttributes.Stride / imageAttributes.Width); } resource.NeedsRefresh = false; } catch (Exception e) { ImageUtils.Log(e); } finally { if (FNeedsConversion) { FBuffer.ReleaseForReading(); } else { FInput.ReleaseForReading(); } } }
public override void Process() { if (FThresholdEnabled) { if (FInput.ImageAttributes.ColourFormat != TColourFormat.L8) { FInput.Image.GetImage(TColourFormat.L8, FOutput.Image); if (DifferenceMode == TDifferenceMode.AbsoluteDifference) { CvInvoke.cvAbsDiff(FOutput.CvMat, FBuffer.CvMat, FOutput.CvMat); } CvInvoke.cvThreshold(FOutput.CvMat, FOutput.CvMat, 255.0d * Threshold, 255, THRESH.CV_THRESH_BINARY); FInput.Image.GetImage(TColourFormat.L8, FBuffer); } else { if (DifferenceMode == TDifferenceMode.AbsoluteDifference) { if (!FInput.LockForReading()) { return; } CvInvoke.cvAbsDiff(FInput.CvMat, FBuffer.CvMat, FOutput.CvMat); FInput.ReleaseForReading(); } CvInvoke.cvThreshold(FOutput.CvMat, FOutput.CvMat, 255.0d * Threshold, 255, THRESH.CV_THRESH_BINARY); } } else { if (DifferenceMode == TDifferenceMode.AbsoluteDifference) { if (!FInput.LockForReading()) { return; } CvInvoke.cvAbsDiff(FInput.CvMat, FBuffer.CvMat, FOutput.CvMat); FInput.ReleaseForReading(); } FBuffer.SetImage(FInput.Image); } FOutput.Send(); }
public override void Evaluate(int spreadMax) { StartEvaluation(); Before(FAgents); var notFailedAgents = from agent in FAgents where agent.ReturnCode != ReturnCodeEnum.Failure select agent; bool pinTrue = IsPinValid(FInput); bool pinFalse = IsPinValid(FInputFalse); var result = Condition(notFailedAgents); int i = 0; foreach (var agent in notFailedAgents) { if (result.ElementAt(i)) { if (pinTrue) { FInput[0].Agents.Add(agent); } } else { if (pinFalse) { FInputFalse[0].Agents.Add(agent); } } i++; } if (pinTrue) { FInput.Sync(); // call child } if (pinFalse) { FInputFalse.Sync(); // call child } After(notFailedAgents); FinishEvaluation(); }
public override void Process() { if (!FInput.LockForReading()) { return; } CvInvoke.cvSetImageROI(FInput.CvMat, CropRectangle); CvInvoke.cvCopy(FInput.CvMat, FOutput.CvMat, IntPtr.Zero); CvInvoke.cvResetImageROI(FInput.CvMat); FInput.ReleaseForReading(); FOutput.Send(); }
public override void Process() { lock (FLockTexture) { //ImageChanged so mark needs refresh on created textures foreach (var key in FNeedsRefresh.Keys.ToList()) { FNeedsRefresh[key] = true; } } if (FNeedsConversion) { FInput.GetImage(FBufferConverted); FBufferConverted.Swap(); } }
public override void Process() { if (Width == 0) { FOutput.Image.SetImage(FInput.Image); } else { if (!FInput.LockForReading()) { return; } CvInvoke.cvSmooth(FInput.CvMat, FOutput.CvMat, SMOOTH_TYPE.CV_GAUSSIAN, Width * 2 + 1, 0, 0, 0); FInput.ReleaseForReading(); } FOutput.Send(); }
public override void Process() { if (!FInput.LockForReading()) { return; } try { CvInvoke.cvSmooth(FInput.CvMat, FOutput.CvMat, SMOOTH_TYPE.CV_GAUSSIAN, Width * 2 + 1, 0, 0, 0); CvInvoke.cvAddWeighted(FInput.CvMat, WeightOrig, FOutput.CvMat, -WeightMask, Gamma, FOutput.CvMat); } finally { FInput.ReleaseForReading(); } FOutput.Send(); }
public override void Process() { if (!FInput.LockForReading()) { return; } CvInvoke.cvAddWeighted(FOutput.CvMat, (double)(FFrame + 1) / (double)FFrames, FInput.CvMat, 1.0 / (double)FFrames, 0, FOutput.CvMat); FInput.ReleaseForReading(); FFrame++; if (FFrame >= FFrames) { FOutput.Send(); CvInvoke.cvSet(FOutput.CvMat, new MCvScalar(0.0), IntPtr.Zero); FFrame = 0; } }
public override void Process() { FInput.LockForReading(); try { switch (DifferenceMode) { case TDifferenceMode.AbsoluteDifference: CvInvoke.cvAbsDiff(FInput.CvMat, FLastFrame.CvMat, FOutput.CvMat); break; case TDifferenceMode.Negative: CvInvoke.cvSub(FInput.CvMat, FLastFrame.CvMat, FOutput.CvMat, new IntPtr()); break; case TDifferenceMode.Positive: CvInvoke.cvSub(FLastFrame.CvMat, FInput.CvMat, FOutput.CvMat, new IntPtr()); break; } } catch { } finally { FInput.ReleaseForReading(); } if (FThresholdEnabled) { if (FInput.ImageAttributes.ColourFormat != TColorFormat.L8) { Status = "Cannot perform threshold on image type " + FInput.ImageAttributes.ColourFormat.ToString() + ". Can only perform threshold on L8"; } else { CvInvoke.cvThreshold(FOutput.CvMat, FOutput.CvMat, 255.0d * Threshold, 255, THRESH.CV_THRESH_BINARY); } } FInput.GetImage(FLastFrame); FOutput.Send(); }
public override void Process() { //Stopwatch sw = new Stopwatch(); //sw.Start(); //Status = ""; if (!FInput.LockForReading()) { return; } FInput.GetImage(FGrayScale); FInput.ReleaseForReading(); FGrayByte = FGrayScale.GetImage() as Image <Gray, byte>; FGrayInt = FGrayByte.Convert <Gray, int>(); //Status += "reading: " + sw.ElapsedMilliseconds.ToString(); //sw.Restart(); PixelWiseDither(); //Status += " dithering: " + sw.ElapsedMilliseconds.ToString(); //sw.Restart(); //try //{ // PixelWiseDither(); //} //catch (Exception e) //{ // Status = e.ToString(); // ImageUtils.Log(e); //} ImageUtils.CopyImage(FGrayInt.Convert <Gray, byte>() as IImage, FOutput.Image); //Status += " writing: " + sw.ElapsedMilliseconds.ToString(); FOutput.Send(); }
public override void Process() { //called on upstream image update if (FNeedsConversion) { FInput.GetImage(FBuffer.BackImage); FBuffer.Swap(); } lock (FLockTexture) { //ImageChanged so mark needs refresh on created textures foreach (var texture in FTextures) { var resource = texture.Value; resource.NeedsRefresh = true; } } }
public override void Evaluate(int SpreadMax) { FInput.Dispose(); for (int i = 0; i < SpreadMax; i++) { Agent agent = FInput[i]; foreach (string name in FPins.Keys) { var pin = ((ISpread <ISpread>)FPins[name].RawIOObject)[i]; agent.Assign(name, pin); } } FOutput.AssignFrom(FInput); FOutput.Flush(); }
public override void Process() { var matrix = new Emgu.CV.Matrix <double>(2, 3); Matrix4x4 transform = new Matrix4x4(); lock (FTransformLock) { //copy the transform out for (int i = 0; i < 16; i++) { transform[i] = FTrasform[i]; } } if (UseCenter) { double halfWidth = FInput.ImageAttributes.Width / 2; double halfHeight = FInput.ImageAttributes.Height / 2; transform = VMath.Translate(-halfWidth, -halfHeight, 0) * transform * VMath.Translate(halfWidth, halfHeight, 0); } matrix[0, 0] = transform[0, 0]; matrix[1, 0] = transform[0, 1]; matrix[0, 1] = transform[1, 0]; matrix[1, 1] = transform[1, 1]; matrix[0, 2] = transform[3, 0]; matrix[1, 2] = transform[3, 1]; if (FInput.LockForReading()) { try { CvInvoke.cvWarpAffine(FInput.CvMat, FOutput.CvMat, matrix.Ptr, (int)Emgu.CV.CvEnum.WARP.CV_WARP_FILL_OUTLIERS, new MCvScalar(0, 0, 0)); } finally { FInput.ReleaseForReading(); } } FOutput.Send(); }
public override void Evaluate(int SpreadMax) { SpreadMax = FInput.SliceCount; if (FInput.IsAnyInvalid()) { SpreadMax = 0; } foreach (string pinName in FPins.Keys) { ((ISpread)FPins[pinName].RawIOObject).SliceCount = SpreadMax; FTimeStamp.SliceCount = SpreadMax; } for (int i = 0; i < SpreadMax; i++) { Agent agent = FInput[i]; FTimeStamp[i] = agent.BirthTime.ToString(); foreach (string name in FPins.Keys) { var pinSpread = (ISpread)((ISpread)FPins[name].RawIOObject)[i]; var bin = agent[name]; pinSpread.SliceCount = bin.Count; for (int j = 0; j < bin.Count; j++) { pinSpread[j] = bin[j]; } } } FOutput.AssignFrom(FInput); FTimeStamp.Flush(); foreach (var pin in FPins.Values) { ((ISpread)pin.RawIOObject).Flush(); } }