Detect Scratches

This code snippet shows how to detect scratches in an image with EasySpotDetector.

C++

#include <eVision/EasySpotDetector/ESpotDetector.h>
using namespace eVision;

// Image constructor
EImageBW8 srcImage;

// Spot detector constructor
ESpotDetector detector;

// Setup the scratch detector parameters with adequate values
EScratchDetectionParameters detectionParams;
detectionParams.Polarity = ESpotPolarity_White;
detectionParams.Threshold = 5;
detectionParams.NominalWidth = 14;
detectionParams.MinLength = 500;
detector.SetScratchDetectionParameters(detectionParams);

// Activate the scratch detection only
detector.SetEnableParticleDetection(false);
detector.SetEnableScratchDetection(true);

// Perform the detection and get the number of detected spots
int32_t nSpot = detector.Detect(srcImage);

// Finally, get the detected spots
std::vector<ESpot> spots = detector.GetSpots();

C#

using eVision;
// Image constructor
EImageBW8 srcImage = new EImageBW8();

// Spot detector constructor
ESpotDetector detector = new ESpotDetector();

// Setup the scratch detector parameters with adequate values
EScratchDetectionParameters detectionParams;
detectionParams.Polarity = ESpotPolarity.White;
detectionParams.Threshold = 5;
detectionParams.NominalWidth = 14;
detectionParams.MinLength = 500;
detector.ScratchDetectionParameters = detectionParams;

// Activate the scratch detection only
detector.EnableParticleDetection = false;
detector.EnableScratchDetection = true;

// Perform the detection and get the number of detected spots
uint nSpot = detector.Detect(srcImage);

// Finally, get the detected spots
ESpot[] spots = detector.Spots;

Python

import eVision

# Image constructor
srcImage = eVision.EImageBW8()

# QR code reader constructor
detector = eVision.ESpotDetector()

# Setup the particle detector parameters with adequate values
detectionParams = eVision.EScratchDetectionParameters()
detectionParams.Polarity = eVision.ESpotPolarity.White
detectionParams.Threshold = 5
detectionParams.NominalWidth = 14
detectionParams.MinLength = 500
detector.ScratchDetectionParameters = detectionParams

# Activate the scratch detection
detector.EnableParticleDetection = False
detector.EnableScratchDetection = True

# Perform the detection and get the number of detected spots
nSpot = detector.Detect(srcImage)

# Finally, get the detected spots
spots = detector.Spots