PoseNet + Processing Error: JSONArray[0] is not a JSONObject

Hi!

I’ve been following Daniel Shiffman’s Runway tutorial on using PoseNet with processing (as an alternative to the ever finnicky Kinect!)

I’m getting the following error right at the end of the tutorial:

RuntimeException: JSONArray[0] is not a JSONObject.

Even though I’ve checked over the code a couple times and it’s the exact same as what is done in the tutorial!

The code is as follows, the third line is what is highlighted in the error:

 if (data != null){
    JSONArray poses = data.getJSONArray("poses");
    ***JSONArray keypoints = poses.getJSONObject(0).getJSONArray("keypoints");***
    JSONObject nose = keypoints.getJSONObject(0);
    JSONObject nosePos = nose.getJSONObject("position");
    float x = nosePos.getFloat("x");
    float y = nosePos.getFloat("y");
    fill(255,0,0);
    ellipse(x,y,20,20);
  }

Thanks in advance!

-a- can you link to where you get the code from?

-b- if the data contain array or object
you can only find out by printing the content

-c- yes, and if we talk about the same structure of data,
https://github.com/runwayml/processing/blob/master/posenet/posenet.pde#L97 ,
indicates it is data.array.array
while you ask for data.array.object.array
but that is all guessing as i not know if we talk about the same data / project / code …
still it would fit to the error msg. you get.

Yes, so the code is from the coding train video above - he didn’t link a github version this time so it’s just word-for-word re-written off the video.

He did use the example you linked, but opted to write new code for that segment to isolate each body part using the data.array.object.array format

I don’t know why it works for him and not for me? Haha. Anyway, I don’t fully understand how to isolate key body points in the example given by runway (the one you linked).

as i say, check on the DATA,
( after learn the basics of JSON )
we have no code, no data, no printout.

I’m sorry I don’t understand.

Earlier in the tutorial this line of code is used to develop the code above:

data = parseJSONObject(dataString);
 println(data);

and the “keypoints”… “poses”… the name of the point (eg. nose) and a whole lot of numbers does print to the console just like in the tutorial… Is this not the data?

good,
and what does it say?
[ ]
says it has a array
{ }
says it has a object …


https://www.w3schools.com/js/js_json_objects.asp
https://www.w3schools.com/js/js_json_arrays.asp

If you head to 19:25 in the video linked above you’ll see that I’ve done exactly what Shiffman has done - So I’m still confused as to why this matters

Why would the code need to be so different for me when I’m using the exact same programs and running it the same way? Why would me using a JSON object at this point be any different to him?

I’d note also that the tutorial was posted less than 2 months ago, so it can’t really be an outdated command…?

did you read the Comments on the video page?

abc def
1 week ago
JSONArray[0] not found
2
Haylee
6 days ago
same error :/
...

Kejia Dai
1 month ago
I followed the tutorial and wrote the processing program, but the  data structure I received from runway/posenet is different from the video.
Mine only has "scores" and "poses", no lable like "parts","posiciton" or "keypoints". And all the numbers in the "poses" array are pretty small like 0.3 or 0.5,
nothing lookis like coordinates. Is this because there is a new version of PosNet?  Is there anyone with the same problem?
1
Jakov Ratkovic
1 month ago
have the same issue
i think its a bug cause you can still acces the objects trough the names

so, no other way!
analyze the data you get!

Ah. I did glance at the comments but only very briefly - didn’t notice any negative ones! Thankyou.
Might just have to keep digging.

1 Like

yes, sorry,

what i not understand is that you avoid

  • to post your full code so someone ?with camera? can run it
  • to post the result of
println(data);

OR

println(dataString);

so we see the obviously changed { [ … ] } structure

i can not promise anything, but why not give someone a chance to help???

Sorry, I was under the impression that we weren’t supposed to paste the full code - lesson learned.

I’ve decided to just use the kinect as I have it working (and I know how to pull specific joints!). With a limited timeframe PoseNet will have to wait until another project.
Thankyou though.

1 Like