I am currently trying to refactor some of my variables that I am using within a View into a struct for clarity. However, when I try to do this, I get a bunch of errors such as Value of type 'Binding<DrawableStaff>' has no dynamic member 'drawings' using key path from root type 'DrawableStaff'.
How do I fix these issues? I have looked into the documentation, and I have looked around online, and I haven't found a solution to this issue.
Here is what the refactored struct looks like
struct DrawableStaff{
		var drawing: Drawing = Drawing()
		var drawingList: [Drawing] = [Drawing]()
		var paths: [Path] = [Path]()
		var PathHolder = Path()
		var color = Color.primary
		var lineWidth: CGFloat = 3.0
}
Here is where DrawableStaff appears in my main ContentView
struct ContentView: View {
		@State private var staff1DrawableStaff = DrawableStaff()		
		var body: some View {
				VStack {						
						let staff1 = ZStack{
								DrawingPad(drawableStaff: $staff1DrawableStaff)
				}
		}
}
Here is where DrawingPad is defined:
struct DrawingPad: View {
		
		@Binding var drawableStaff: DrawableStaff
		
		var body: some View {
				GeometryReader { geometry in
						Path { path in
								for drawing in self.drawableStaff.drawings {
										self.add(drawing: drawableStaff.drawing, toPath: &path)
								}
								self.add(drawing: self.drawableStaff.currentDrawing, toPath: &path)
								self.drawableStaff.pathHolder = path
						}
						.stroke(self.drawableStaff.color, lineWidth: self.drawableStaff.lineWidth)
								.background(Color(UIColor.systemBackground))
								.gesture(
										DragGesture(minimumDistance: 0.1)
												.onChanged({ (value) in
														let currentPoint = value.location
														if currentPoint.y >= 0
																&& currentPoint.y < geometry.size.height {
																self.drawableStaff.currentDrawing.points.append(currentPoint)
														}
												})
												.onEnded({ (value) in
														self.drawableStaff.drawings.append(self.currentDrawing)
														self.drawableStaff.currentDrawing = Drawing()
												})
						)
												
						
				}
				.frame(maxHeight: .infinity)
		}
private func add(drawing: Drawing, toPath path: inout Path) {
let points = drawing.points
if points.count > 1 {
for i in 0..<points.count-1 {
let current = points[i]
let next = points[i+1]
path.move(to: current)
path.addLine(to: next)
}
}
}
}
Here is my Drawing definition:
struct Drawing {
var points: [CGPoint] = [CGPoint]()
}
Post
Replies
Boosts
Views
Activity
I am working on an app that classifies drawings made by user. Currently, the user made drawings are represented as a set of SwiftUI Paths, and I have a trained Core ML model that takes images and outputs class names.
I have written some code that is able to take in images in the form of UIImages and feed it into my classifier, but I am unsure of how I should adapt my code to take Paths.
Here is my current code:
import UIKit
import CoreML
import Vision
import ImageIO
import SwiftUI
struct ImageClassifier{
		var classifier = SymbolClassifier()
		func classify(image: CGImage) -> String?{
				let pixelBuffer = image.pixelBuffer(width: 300, height: 300, orientation: CGImagePropertyOrientation.up)!
				let output = try? self.classifier.prediction(image: pixelBuffer)
				return output?.classLabel
		}
		func classifyUIImage(image: UIImage)-> String?{
				guard let imageAsUIImage:CGImage = convertUIImageToCGImage(image: image) else{
						return nil
				}
				return classify(image: imageAsUIImage)
		}
		func classifyPath(path:Path) -> String?{
				//???
				return nil
		}
		func convertUIImageToCGImage(image: UIImage) -> CGImage? {
				let inputImage = CIImage(image: image)!
				let context = CIContext(options: nil)
				return context.createCGImage(inputImage, from: inputImage.extent)
		}
}
Here - https://github.com/ivyjsgit/Manuscript-iOS/blob/main/Manuscript/Libraries/CGImage%2BCVPixelBuffer.swift is the image.pixelBuffer library and here - https://github.com/ivyjsgit/Manuscript-iOS/blob/main/Manuscript/Manuscript/SymbolClassifier.mlmodel is the model
I am attempting to load a set of images into Create ML so that I can train an image classifier model. However, when I select the folder that my training data is in, I get the error "No training data found. 0 invalid files found."
My data is laid out as such.
Parent folder
-Training data (Selected in Create ML)
-Individuals for each class
-Image files
-Test data
-Individuals for each class
-Image files
My dataset can be viewed here - https://github.com/ivyjsgit/HOMUS-Bitmap/tree/master/Splitted