Using Google Vision (CURL through a shell script) I’m pulling in json so that I can capture values to crop images in photoshop.
I’m having a difficult time grabbing the values I need.
The data returned looks like this:
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 541k 0 0 100 541k 0 3419k --:--:-- --:--:-- --:--:-- 3408k
100 543k 0 1838 100 541k 3805 1121k --:--:-- --:--:-- --:--:-- 1121k
{
"responses": [
{
"localizedObjectAnnotations": [
{
"mid": "/m/07mhn",
"name": "Pants",
"score": 0.9494914,
"boundingPoly": {
"normalizedVertices": [
{
"x": 0.3794051,
"y": 0.49376252
},
{
"x": 0.623296,
"y": 0.49376252
},
{
"x": 0.623296,
"y": 0.96466535
},
{
"x": 0.3794051,
"y": 0.96466535
}
]
}
},
{
"mid": "/m/03gx245",
"name": "Top",
"score": 0.93232113,
"boundingPoly": {
"normalizedVertices": [
{
"x": 0.33775452,
"y": 0.08114735
},
{
"x": 0.6737402,
"y": 0.08114735
},
{
"x": 0.6737402,
"y": 0.54397774
},
{
"x": 0.33775452,
"y": 0.54397774
}
]
}
},
{
"mid": "/m/01g317",
"name": "Person",
"score": 0.850009,
"boundingPoly": {
"normalizedVertices": [
{
"x": 0.32060996,
"y": 0.013396601
},
{
"x": 0.6699771,
"y": 0.013396601
},
{
"x": 0.6699771,
"y": 0.9879022
},
{
"x": 0.32060996,
"y": 0.9879022
}
]
}
}
]
}
]
}
My end goal is to say something like
if name = "pants" then
//return the X and Y vertices for the pants object
//do some math to turn them into actual coordinates that I can then send to Photoshop
end if
I guess I’m just unsure on how to achieve this in Xojo.
My regex pattern of ("normalizedVertices"\s*:\s*(?:\[[^]]*]|[^,}]+))
grabs every chunk of coordinates. Great.
Also, (?:"name"\s*:\s*)("Pants")
gives me the word “Pants”.
Alright…
Where do I go from here? How can I make the connection between “Pants” and the 4 sets of vertices that correspond to it?