there is four arrays:
first id with pixel coordinates second with pixel colours third with searched colours in second (e.q. all picture contains only two colours ) fourth must contains colours and pixel coordinates, where coordinates collected on colour
I try to compare two arrays (#2 and #3) and if result is true add an member from the another array (#1) in the array #4
when code execute, it take me mistake with last compare operator (if (rgbAr == crD) {)
import Cocoa
class ViewController: NSViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override var representedObject: Any? {
didSet {
// Update the view, if already loaded.
}
}
@IBAction func passPix(_ sender: Any) {
let fileURL = "/Users/IMac/Desktop/text.txt"
var inString = ("Pix+Col")
do {
inString = try String(contentsOfFile: fileURL, encoding:String.Encoding.utf8)
} catch let error as NSError {
print("Failed reading from URL: \(fileURL), Error: " + error.localizedDescription)
}
var js = String(inString.characters.map { $0 == "(" ? "[" : $0 })
js = String(js.characters.map { $0 == ")" ? "]" : $0 })
let data = js.data(using: .utf8)
let json = try! JSONSerialization.jsonObject(with: data!) as! [Any]
let coords = json[0] as! [NSArray]
let rgbs = json[1] as! [NSArray]
var array = [Array<Double>] ()
var newrgbs = [Array <Double>] ()
var coords_1 = [Array <Double>] ()
var separCol = [Array <Double>] ()
let firstEl = rgbs [0]
let FirstElem = [firstEl [0] as! Double, firstEl [1] as!Double, firstEl [2] as!Double]
array.append (FirstElem)
for itt in coords{
let itemX = [itt[0] as! Double, itt [1] as!Double]
coords_1.append(itemX)
}
for item in rgbs{
let itemX = [item [0] as! Double, item [1] as!Double, item [2] as!Double]
newrgbs.append(itemX)
let result = array.filter { $0==itemX }
if result.isEmpty {
array.append(itemX)
}
}
for rgbAr in array {
var inteR = 0
separCol.append (rgbAr)
for crD in newrgbs{
inteR += 1
if (rgbAr == crD) {
separCol.append (coords_1 [25])
}
}
}
print (separCol)
}
}
Aucun commentaire:
Enregistrer un commentaire