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 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() { if (!FInput.LockForReading()) { return; } CvInvoke.cvCmpS(FInput.CvMat, Threshold, FOutput.CvMat, CMP_TYPE.CV_CMP_LT); FInput.ReleaseForReading(); 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() { 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() { 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 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() { 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() { 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 Process() { if (FSave) { FSave = false; try { FInput.LockForReading(); FInput.Image.SaveFile(FFilename); FInput.ReleaseForReading(); this.Status = "OK"; this.Success = true; } catch (Exception e) { this.Status = e.Message; } } }
public override void Process() { if (FNeedsConversion) { FInput.GetImage(FGrayscale); CvInvoke.cvCanny(FGrayscale.CvMat, FOutput.CvMat, ThresholdMin, ThresholdMax, FAperture); } else { FInput.LockForReading(); try { CvInvoke.cvCanny(FInput.CvMat, FOutput.CvMat, ThresholdMin, ThresholdMax, FAperture); } finally { FInput.ReleaseForReading(); } } FOutput.Send(); }
public override void Process() { if (FInput.ImageAttributes.ChannelCount == 1) { if (!FInput.LockForReading()) { return; } try { Compare(FInput.CvMat); } finally { FInput.ReleaseForReading(); } } else { FInput.GetImage(Buffer); Compare(Buffer.CvMat); } if (FPassOriginal) { FOutput.Image.SetImage(FInput.Image); } if (FPassOriginal) { CvInvoke.cvNot(Buffer.CvMat, Buffer.CvMat); CvInvoke.cvSet(FOutput.Image.CvMat, new MCvScalar(0.0), Buffer.CvMat); FOutput.Send(); } else { FOutput.Send(Buffer); } }
public override void Process() { //we have an integer number of steps int anticlockwiseSteps = VVVV.Utils.VMath.VMath.Zmod(Rotations, 4); bool transpose = anticlockwiseSteps % 2 == 1; Size outputSize = transpose ? new Size(FInput.Image.Size.Height, FInput.Image.Size.Width) : FInput.Image.Size; if (FOutput.Image.Size != outputSize || FOutput.Image.NativeFormat != FInput.Image.NativeFormat) { FOutput.Image.Initialise(outputSize, FInput.Image.NativeFormat); } switch (anticlockwiseSteps) { case 0: FInput.GetImage(FOutput.Image); break; case 1: if (FInput.LockForReading()) { try { CvInvoke.cvTranspose(FInput.CvMat, FOutput.CvMat); } finally { FInput.ReleaseForReading(); } CvInvoke.cvFlip(FOutput.CvMat, FOutput.CvMat, FLIP.VERTICAL); } break; case 2: if (FInput.LockForReading()) { try { CvInvoke.cvFlip(FInput.CvMat, FOutput.CvMat, FLIP.HORIZONTAL); } finally { FInput.ReleaseForReading(); } CvInvoke.cvFlip(FOutput.CvMat, FOutput.CvMat, FLIP.VERTICAL); } break; case 3: if (FInput.LockForReading()) { try { CvInvoke.cvTranspose(FInput.CvMat, FOutput.CvMat); } finally { FInput.ReleaseForReading(); } CvInvoke.cvFlip(FOutput.CvMat, FOutput.CvMat, FLIP.HORIZONTAL); } break; } FOutput.Send(); }
public void UpdateTexture(Texture texture) { lock (FLockTexture) { if (!InputOK) { return; } if (!FNeedsRefresh.ContainsKey(texture)) { FNeedsTexture = true; return; } if (!FNeedsRefresh[texture]) { return; } if (FInput.ImageAttributesChanged) { return; } bool ex = texture.Device is DeviceEx; Surface srf = texture.GetSurfaceLevel(0); DataRectangle rect = srf.LockRectangle(ex ? LockFlags.Discard : LockFlags.None); try { Size imageSize = FNeedsConversion ? FBufferConverted.ImageAttributes.Size : FInput.ImageAttributes.Size; if (srf.Description.Width != imageSize.Width || srf.Description.Height != imageSize.Height) { throw (new Exception("AsTextureInstance : srf dimensions don't match image dimensions")); } if (!FInput.Image.Allocated) { throw (new Exception("Image not allocated")); } if (FNeedsConversion) { FInput.GetImage(FBufferConverted); FBufferConverted.Swap(); FBufferConverted.LockForReading(); try { if (!FBufferConverted.FrontImage.Allocated) { throw (new Exception()); } if (rect.Pitch == FBufferConverted.ImageAttributes.Stride) { rect.Data.WriteRange(FBufferConverted.FrontImage.Data, FBufferConverted.ImageAttributes.BytesPerFrame); } else { //copy full lines for (int i = 0; i < FBufferConverted.ImageAttributes.Height; i++) { Memory.Copy(rect.Data.DataPointer.Move(rect.Pitch * i), FBufferConverted.FrontImage.Data.Move(FBufferConverted.ImageAttributes.Stride * i), (uint)FBufferConverted.ImageAttributes.Stride); } } FNeedsRefresh[texture] = false; } catch (Exception e) { ImageUtils.Log(e); } finally { FBufferConverted.ReleaseForReading(); } } else { FInput.LockForReading(); try { rect.Data.WriteRange(FInput.Data, FInput.ImageAttributes.BytesPerFrame); FNeedsRefresh[texture] = false; } catch (Exception e) { ImageUtils.Log(e); } finally { FInput.ReleaseForReading(); } } } catch (Exception e) { Logger.Log(e); } finally { srf.UnlockRectangle(); } } }
public void UpdateTexture(Texture texture) { lock (FLockTexture) { if (!FNeedsRefresh.ContainsKey(texture)) { FNeedsTexture = true; return; } if (!FNeedsRefresh[texture]) { return; } if (FInput.ImageAttributesChanged) { //reset flag we just dropped FInput.ImageAttributesChanged = true; return; } FNeedsRefresh[texture] = false; Surface srf = texture.GetSurfaceLevel(0); DataRectangle rect = srf.LockRectangle(LockFlags.Discard); if (FNeedsConversion) { if (!FBufferConverted.Allocated) { srf.UnlockRectangle(); return; } FInput.GetImage(FBufferConverted); FBufferConverted.LockForReading(); try { rect.Data.WriteRange(FBufferConverted.FrontImage.Data, FBufferConverted.ImageAttributes.BytesPerFrame); } finally { FBufferConverted.ReleaseForReading(); } } else { FInput.LockForReading(); try { rect.Data.WriteRange(FInput.Data, FInput.ImageAttributes.BytesPerFrame); } catch (Exception e) { ImageUtils.Log(e); } finally { FInput.ReleaseForReading(); } } srf.UnlockRectangle(); } }
public void UpdateTexture(Texture texture) { lock (FLockTexture) { if (!InputOK) { return; } if (!FNeedsRefresh.ContainsKey(texture)) { FNeedsTexture = true; return; } if (!FNeedsRefresh[texture]) { return; } if (FInput.ImageAttributesChanged) { //reset flag we just dropped FInput.ImageAttributesChanged = true; return; } Surface srf = texture.GetSurfaceLevel(0); DataRectangle rect = srf.LockRectangle(LockFlags.Discard); try { Size imageSize = FNeedsConversion ? FBufferConverted.ImageAttributes.Size : FInput.ImageAttributes.Size; if (srf.Description.Width != imageSize.Width || srf.Description.Height != imageSize.Height) { throw (new Exception("AsTextureInstance : srf dimensions don't match image dimensions")); } if (FNeedsConversion) { FInput.GetImage(FBufferConverted); FBufferConverted.Swap(); FBufferConverted.LockForReading(); try { if (!FBufferConverted.FrontImage.Allocated) { throw (new Exception()); } rect.Data.WriteRange(FBufferConverted.FrontImage.Data, FBufferConverted.ImageAttributes.BytesPerFrame); FNeedsRefresh[texture] = false; } catch (Exception e) { ImageUtils.Log(e); } finally { FBufferConverted.ReleaseForReading(); } } else { FInput.LockForReading(); try { rect.Data.WriteRange(FInput.Data, FInput.ImageAttributes.BytesPerFrame); FNeedsRefresh[texture] = false; } catch (Exception e) { ImageUtils.Log(e); } finally { FInput.ReleaseForReading(); } } } catch (Exception e) { throw (e); } finally { srf.UnlockRectangle(); } } }