Skip to content

Instantly share code, notes, and snippets.

@xellDart
xellDart / btc.dart
Created November 7, 2019 04:33
Bitcoin address validation
/*
* Bitcoin address validation - xellDart.
*
*/
import 'package:crypto/crypto.dart';
class Bitcoin {
final String ALPHABET =
"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
class OptionsFace {
final int numClasses;
final int numBoxes;
final int numCoords;
final int keypointCoordOffset;
final List<int> ignoreClasses;
final double scoreClippingThresh;
final double minScoreThresh;
final int numKeypoints;
final int numValuesPerKeypoint;
class AnchorOption {
final int inputSizeWidth;
final int inputSizeHeight;
final double minScale;
final double maxScale;
final double anchorOffsetX;
final double anchorOffsetY;
final int numLayers;
final List<int> featureMapWidth;
final List<int> featureMapHeight;
class Detection {
final double score;
final int classID;
final double xMin;
final double yMin;
final double width;
final double height;
Detection(
this.score, this.classID, this.xMin, this.yMin, this.width, this.height);
}
@xellDart
xellDart / face.dart
Last active February 14, 2021 18:21
// Load model
void _loadModel() async {
_anchors = UtilsFace().getAnchors(anchors);
_interpreter =
await Interpreter.fromAsset("models/face_detection_front.tflite");
_inputShape = _interpreter.getInputTensor(0).shape;
_imageProcessor = ImageProcessorBuilder()
.add(ResizeOp(
_inputShape[1], _inputShape[2], ResizeMethod.NEAREST_NEIGHBOUR))
.add(_normalizeInput)
List<Detection> process(
{OptionsFace options,
List<double> rawScores,
List<double> rawBoxes,
List<Anchor> anchors}) {
List<double> detectionScores = new List();
List<int> detectionClasses = new List();
int boxes = options.numBoxes;
for (int i = 0; i < boxes; i++) {
List<Anchor> getAnchors(AnchorOption options) {
List<Anchor> _anchors = new List();
if (options.stridesSize != options.numLayers) {
print('strides_size and num_layers must be equal.');
return [];
}
int layerID = 0;
while (layerID < options.stridesSize) {
List<double> anchorHeight = new List();
List<double> anchorWidth = new List();
Detection convertToDetection(double boxYMin, double boxXMin, double boxYMax,
double boxXMax, double score, int classID, bool flipVertically) {
double _yMin;
if (flipVertically)
_yMin = 1.0 - boxYMax;
else
_yMin = boxYMin;
return new Detection(score, classID, boxXMin, _yMin, (boxXMax - boxXMin),
(boxXMax - boxYMin));
}
Array decodeBox(
List<double> rawBoxes, int i, List<Anchor> anchors, OptionsFace options) {
Array boxData = Array(List<double>.generate(options.numCoords, (i) => 0.0));
int boxOffset = i * options.numCoords + options.boxCoordOffset;
double yCenter = rawBoxes[boxOffset];
double xCenter = rawBoxes[boxOffset + 1];
double h = rawBoxes[boxOffset + 2];
double w = rawBoxes[boxOffset + 3];
if (options.reverseOutputOrder) {
xCenter = rawBoxes[boxOffset];
List<Detection> origNms(List<Detection> detections, double threshold) {
if (detections.length <= 0) return [];
List<double> x1 = new List();
List<double> x2 = new List();
List<double> y1 = new List();
List<double> y2 = new List();
List<double> s = new List();
detections.forEach((detection) {
x1.add(detection.xMin);