Created
December 18, 2020 00:24
-
-
Save ntjess/84f2f6881fe3a1783398193739ba5f20 to your computer and use it in GitHub Desktop.
Minimal example for 'via' detection in s3a
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import cv2 as cv | |
from s3a import FR_SINGLETON, ComplexXYVertices, REQD_TBL_FIELDS as RTF, S3A, appInst | |
from s3a.processing import ProcessIO | |
from s3a.processing.processing import GlobalPredictionProcess | |
from pyqtgraph.Qt import QtCore | |
def findCircles(image: np.ndarray, nCircles=5, minRadius=6, maxRadius=200): | |
# row-col to x-y | |
shape = image.shape[:2][::-1] | |
originPts = np.random.randint((0), shape, (nCircles,2)) | |
radii = np.random.randint(minRadius, maxRadius, nCircles) | |
outImg = np.zeros(image.shape[:2], dtype='uint8') | |
verts = [] | |
for pt, rad in zip(originPts, radii): | |
outImg.fill(0) | |
cv.circle(outImg, tuple(pt), rad, 1, -1) | |
verts.append(ComplexXYVertices.fromBwMask(outImg)) | |
outComps = FR_SINGLETON.tableData.makeCompDf(nCircles).reset_index(drop=True) | |
outComps[RTF.VERTICES] = verts | |
return ProcessIO(components=outComps, deleteOrigs=False) | |
FR_SINGLETON.globalPredClctn.addProcessFunction(findCircles, GlobalPredictionProcess) | |
win = S3A(loadLastState=True) | |
QtCore.QTimer.singleShot(0, win.showMaximized) | |
appInst.exec_() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment