Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Selfie Segmentation data casting #473

Merged
merged 1 commit into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,14 @@ class DetectedObject {

/// Returns an instance of [DetectedObject] from a given [json].
factory DetectedObject.fromJson(Map<dynamic, dynamic> json) {
final rect = RectJson.fromJson(json['rect']);
final boundingBox = RectJson.fromJson(json['rect']);
final trackingId = json['trackingId'];
final labels = <Label>[];
for (final dynamic label in json['labels']) {
labels.add(Label.fromJson(label));
}
return DetectedObject(
boundingBox: rect,
boundingBox: boundingBox,
labels: labels,
trackingId: trackingId,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,15 @@ class SegmentationMask {

/// Returns an instance of [SegmentationMask] from a given [json].
factory SegmentationMask.fromJson(Map<dynamic, dynamic> json) {
final values = json['confidences'];
final List<double> confidences = [];
for (final item in values) {
confidences.add(double.parse(item.toString()));
}
return SegmentationMask(
width: json['width'] as int,
height: json['height'] as int,
confidences: json['confidences'] as List<double>,
confidences: confidences,
);
}
}
32 changes: 16 additions & 16 deletions packages/google_mlkit_text_recognition/lib/src/text_recognizer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ class TextBlock {
/// Returns an instance of [TextBlock] from a given [json].
factory TextBlock.fromJson(Map<dynamic, dynamic> json) {
final text = json['text'];
final rect = RectJson.fromJson(json['rect']);
final boundingBox = RectJson.fromJson(json['rect']);
final recognizedLanguages =
_listToRecognizedLanguages(json['recognizedLanguages']);
final points = _listToCornerPoints(json['points']);
final cornerPoints = _listToCornerPoints(json['points']);
final lines = <TextLine>[];
for (final line in json['lines']) {
final textLine = TextLine.fromJson(line);
Expand All @@ -107,9 +107,9 @@ class TextBlock {
return TextBlock(
text: text,
lines: lines,
boundingBox: rect,
boundingBox: boundingBox,
recognizedLanguages: recognizedLanguages,
cornerPoints: points,
cornerPoints: cornerPoints,
);
}
}
Expand Down Expand Up @@ -153,12 +153,12 @@ class TextLine {
/// Returns an instance of [TextLine] from a given [json].
factory TextLine.fromJson(Map<dynamic, dynamic> json) {
final text = json['text'];
final rect = RectJson.fromJson(json['rect']);
final boundingBox = RectJson.fromJson(json['rect']);
final confidence = json['confidence'];
final angle = json['angle'];
final recognizedLanguages =
_listToRecognizedLanguages(json['recognizedLanguages']);
final points = _listToCornerPoints(json['points']);
final cornerPoints = _listToCornerPoints(json['points']);
final elements = <TextElement>[];
for (final element in json['elements']) {
final textElement = TextElement.fromJson(element);
Expand All @@ -167,9 +167,9 @@ class TextLine {
return TextLine(
text: text,
elements: elements,
boundingBox: rect,
boundingBox: boundingBox,
recognizedLanguages: recognizedLanguages,
cornerPoints: points,
cornerPoints: cornerPoints,
confidence: confidence,
angle: angle,
);
Expand Down Expand Up @@ -216,10 +216,10 @@ class TextElement {
/// Returns an instance of [TextElement] from a given [json].
factory TextElement.fromJson(Map<dynamic, dynamic> json) {
final text = json['text'];
final rect = RectJson.fromJson(json['rect']);
final boundingBox = RectJson.fromJson(json['rect']);
final recognizedLanguages =
_listToRecognizedLanguages(json['recognizedLanguages']);
final points = _listToCornerPoints(json['points']);
final cornerPoints = _listToCornerPoints(json['points']);
final confidence = json['confidence'];
final angle = json['angle'];
final symbols = <TextSymbol>[];
Expand All @@ -230,9 +230,9 @@ class TextElement {
return TextElement(
text: text,
symbols: symbols,
boundingBox: rect,
boundingBox: boundingBox,
recognizedLanguages: recognizedLanguages,
cornerPoints: points,
cornerPoints: cornerPoints,
confidence: confidence,
angle: angle,
);
Expand Down Expand Up @@ -274,17 +274,17 @@ class TextSymbol {
/// Returns an instance of [TextSymbol] from a given [json].
factory TextSymbol.fromJson(Map<dynamic, dynamic> json) {
final text = json['text'];
final rect = RectJson.fromJson(json['rect']);
final boundingBox = RectJson.fromJson(json['rect']);
final recognizedLanguages =
_listToRecognizedLanguages(json['recognizedLanguages']);
final points = _listToCornerPoints(json['points']);
final cornerPoints = _listToCornerPoints(json['points']);
final confidence = json['confidence'];
final angle = json['angle'];
return TextSymbol(
text: text,
boundingBox: rect,
boundingBox: boundingBox,
recognizedLanguages: recognizedLanguages,
cornerPoints: points,
cornerPoints: cornerPoints,
confidence: confidence,
angle: angle,
);
Expand Down