mirror of
https://github.com/riegera2412/UVtools.git
synced 2026-07-09 01:52:32 +02:00
5cfd62d36e
* (Add) Tools can now run inside a ROI (#49) * (Add) Layer preview: Hold-Shift + Left-drag to select an ROI (Region of interest) on image, that region will be used instead of whole image when running some tools * (Add) Layer preview: Hold-Shift + Hold-Alt + Left-drag to select and auto adjust the ROI to the contained objects, that region will be used instead of whole image when running some tools * (Add) Layer preview: Hold-Shift + Right-click on a object to select its bounding area, that region will be used instead of whole image when running some tools * (Add) Layer preview: ESC key to clear ROI * (Add) Layer preview: Overlay text with hints for current action * (Add) Tool - Move: Now possible to do a copy move instead of a cut move * (Add) Arrow wait cursor to progress loadings * (Change) Layer preview: Hold-Shift key to select issues and pick pixel position/brightness changed to Hold-Control key * (Change) Layer preview: Shift+click combination to zoom-in changed to Alt+click * (Fix) CTB v3: Bad file when re-encoding
80 lines
2.0 KiB
C#
80 lines
2.0 KiB
C#
using System;
|
|
using Emgu.CV;
|
|
using Emgu.CV.CvEnum;
|
|
using Emgu.CV.Util;
|
|
|
|
namespace UVtools.GUI
|
|
{
|
|
public sealed class LayerCache
|
|
{
|
|
private Mat _image;
|
|
private Array _layerHierarchyJagged;
|
|
private VectorOfVectorOfPoint _layerContours;
|
|
private Mat _layerHierarchy;
|
|
|
|
public Mat Image
|
|
{
|
|
get => _image;
|
|
set
|
|
{
|
|
Clear();
|
|
_image = value;
|
|
}
|
|
}
|
|
|
|
public VectorOfVectorOfPoint LayerContours
|
|
{
|
|
get
|
|
{
|
|
if (_layerContours is null) CacheContours();
|
|
return _layerContours;
|
|
}
|
|
private set => _layerContours = value;
|
|
}
|
|
|
|
public Mat LayerHierarchy
|
|
{
|
|
get
|
|
{
|
|
if (_layerHierarchy is null) CacheContours();
|
|
return _layerHierarchy;
|
|
}
|
|
private set => _layerHierarchy = value;
|
|
}
|
|
|
|
public Array LayerHierarchyJagged
|
|
{
|
|
get
|
|
{
|
|
if(_layerHierarchyJagged is null) CacheContours();
|
|
return _layerHierarchyJagged;
|
|
}
|
|
private set => _layerHierarchyJagged = value;
|
|
}
|
|
|
|
public void CacheContours(bool refresh = false)
|
|
{
|
|
if(refresh) Clear();
|
|
if (!ReferenceEquals(_layerContours, null)) return;
|
|
_layerContours = new VectorOfVectorOfPoint();
|
|
_layerHierarchy = new Mat();
|
|
CvInvoke.FindContours(Image, _layerContours, _layerHierarchy, RetrType.Ccomp,
|
|
ChainApproxMethod.ChainApproxSimple);
|
|
_layerHierarchyJagged = _layerHierarchy.GetData();
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Clears the cache
|
|
/// </summary>
|
|
public void Clear()
|
|
{
|
|
_layerContours?.Dispose();
|
|
_layerContours = null;
|
|
_layerHierarchy?.Dispose();
|
|
_layerHierarchy = null;
|
|
_layerHierarchyJagged = null;
|
|
}
|
|
}
|
|
}
|