After using findContours function I am getting an output but i only want to access the elements inside it one by one


After using the finContours function I got an output which is shown in the image. How can i access them one by one so that i could pass them inside my show function which takes areguments like this:
show(%Evision.Mat{channels: _, dims: _, raw_type: _, ref: image, shape: _, type: _})

Can someone help me out?

Hi @Harsh00988, next time please copy and paste the values here instead of using a screenshot.

It looks like the return value is a tuple, where the first element is your list of data, and the rest of it can’t be seen in your screen shot. Try pattern matching out the list or using elem/2 to extract the list from the tuple.

Thank you so much for your help.

{[
   %Evision.Mat{
     channels: 2,
     dims: 2,
     raw_type: 12,
     ref: #Reference<0.791848197.4210950176.188974>,
     shape: {576, 1, 2},
     type: {:s, 32}
   },
   %Evision.Mat{
     channels: 2,
     dims: 2,
     raw_type: 12,
     ref: #Reference<0.791848197.4210950176.188975>,
     shape: {522, 1, 2},
     type: {:s, 32}
   },
   %Evision.Mat{
     channels: 2,
     dims: 2,
     raw_type: 12,
     ref: #Reference<0.791848197.4210950176.188976>,
     shape: {1038, 1, 2},
     type: {:s, 32}
   },
   %Evision.Mat{
     channels: 2,
     dims: 2,
     raw_type: 12,
     ref: #Reference<0.791848197.4210950176.188977>,
     shape: {1036, 1, 2},
     type: {:s, 32}
   },
   %Evision.Mat{
     channels: 2,
     dims: 2,
     raw_type: 12,
     ref: #Reference<0.791848197.4210950176.188978>,
     shape: {1038, 1, 2},
     type: {:s, 32}
   },
   %Evision.Mat{
     channels: 2,
     dims: 2,
     raw_type: 12,
     ref: #Reference<0.791848197.4210950176.188979>,
     shape: {119, 1, 2},
     type: {:s, 32}
   },
   %Evision.Mat{
     channels: 2,
     dims: 2,
     raw_type: 12,
     ref: #Reference<0.791848197.4210950176.188980>,
     shape: {449, 1, 2},
     type: {:s, 32}
   },
   %Evision.Mat{
     channels: 2,
     dims: 2,
     raw_type: 12,
     ref: #Reference<0.791848197.4210950176.188981>,
     shape: {368, 1, 2},
     type: {:s, 32}
   },
   %Evision.Mat{
     channels: 2,
     dims: 2,
     raw_type: 12,
     ref: #Reference<0.791848197.4210950176.188982>,
     shape: {1050, 1, 2},
     type: {:s, 32}
   },
   %Evision.Mat{
     channels: 2,
     dims: 2,
     raw_type: 12,
     ref: #Reference<0.791848197.4210950176.188983>,
     shape: {1048, 1, 2},
     type: {:s, 32}
   },
   %Evision.Mat{
     channels: 2,
     dims: 2,
     raw_type: 12,
     ref: #Reference<0.791848197.4210950176.188984>,
     shape: {1050, 1, 2},
     type: {:s, 32}
   },
   %Evision.Mat{
     channels: 2,
     dims: 2,
     raw_type: 12,
     ref: #Reference<0.791848197.4210950176.188985>,
     shape: {521, 1, 2},
     type: {:s, 32}
   },
   %Evision.Mat{
     channels: 2,
     dims: 2,
     raw_type: 12,
     ref: #Reference<0.791848197.4210950176.188986>,
     shape: {520, 1, 2},
     type: {:s, 32}
   },
   %Evision.Mat{
     channels: 2,
     dims: 2,
     raw_type: 12,
     ref: #Reference<0.791848197.4210950176.188987>,
     shape: {1050, 1, 2},
     type: {:s, 32}
   },
   %Evision.Mat{
     channels: 2,
     dims: 2,
     raw_type: 12,
     ref: #Reference<0.791848197.4210950176.188988>,
     shape: {1048, 1, 2},
     type: {:s, 32}
   },
   %Evision.Mat{
     channels: 2,
     dims: 2,
     raw_type: 12,
     ref: #Reference<0.791848197.4210950176.188989>,
     shape: {1050, 1, 2},
     type: {:s, 32}
   },
   %Evision.Mat{
     channels: 2,
     dims: 2,
     raw_type: 12,
     ref: #Reference<0.791848197.4210950176.188990>,
     shape: {3276, 1, 2},
     type: {:s, 32}
   },
   %Evision.Mat{
     channels: 2,
     dims: 2,
     raw_type: 12,
     ref: #Reference<0.791848197.4210950176.188991>,
     shape: {13, 1, 2},
     type: {:s, 32}
   },
   %Evision.Mat{
     channels: 2,
     dims: 2,
     raw_type: 12,
     ref: #Reference<0.791848197.4210950176.188992>,
     shape: {50, 1, 2},
     type: {:s, 32}
   },
   %Evision.Mat{
     channels: 2,
     dims: 2,
     raw_type: 12,
     ref: #Reference<0.791848197.4210950176.188993>,
     shape: {20, 1, 2},
     type: {:s, 32}
   },
   %Evision.Mat{
     channels: 2,
     dims: 2,
     raw_type: 12,
     ref: #Reference<0.791848197.4210950176.188994>,
     shape: {21, 1, 2},
     type: {:s, 32}
   },
   %Evision.Mat{
     channels: 2,
     dims: 2,
     raw_type: 12,
     ref: #Reference<0.791848197.4210950176.188995>,
     shape: {21, 1, 2},
     type: {:s, 32}
   },
   %Evision.Mat{
     channels: 2,
     dims: 2,
     raw_type: 12,
     ref: #Reference<0.791848197.4210950176.188996>,
     shape: {13, 1, 2},
     type: {:s, 32}
   },
   %Evision.Mat{
     channels: 2,
     dims: 2,
     raw_type: 12,
     ref: #Reference<0.791848197.4210950176.188997>,
     shape: {12, 1, 2},
     type: {:s, 32}
   },
   %Evision.Mat{
     channels: 2,
     dims: 2,
     raw_type: 12,
     ref: #Reference<0.791848197.4210950176.188998>,
     shape: {21, 1, 2},
     type: {:s, 32}
   },
   %Evision.Mat{
     channels: 2,
     dims: 2,
     raw_type: 12,
     ref: #Reference<0.791848197.4210950176.188999>,
     shape: {20, 1, 2},
     type: {:s, 32}
   },
   %Evision.Mat{
     channels: 2,
     dims: 2,
     raw_type: 12,
     ref: #Reference<0.791848197.4210950176.189000>,
     shape: {13, 1, 2},
     type: {:s, 32}
   },
   %Evision.Mat{
     channels: 2,
     dims: 2,
     raw_type: 12,
     ref: #Reference<0.791848197.4210950176.189001>,
     shape: {13, 1, 2},
     type: {:s, 32}
   },
   %Evision.Mat{
     channels: 2,
     dims: 2,
     raw_type: 12,
     ref: #Reference<0.791848197.4210950176.189002>,
     shape: {21, 1, 2},
     type: {:s, 32}
   },
   %Evision.Mat{
     channels: 2,
     dims: 2,
     raw_type: 12,
     ref: #Reference<0.791848197.4210950176.189003>,
     shape: {78, 1, 2},
     type: {:s, 32}
   },
   %Evision.Mat{
     channels: 2,
     dims: 2,
     raw_type: 12,
     ref: #Reference<0.791848197.4210950176.189004>,
     shape: {34, 1, 2},
     type: {:s, 32}
   },
   %Evision.Mat{
     channels: 2,
     dims: 2,
     raw_type: 12,
     ref: #Reference<0.791848197.4210950176.189005>,
     shape: {32, 1, 2},
     type: {:s, 32}
   },
   %Evision.Mat{
     channels: 2,
     dims: 2,
     raw_type: 12,
     ref: #Reference<0.791848197.4210950176.189006>,
     shape: {33, 1, 2},
     type: {:s, 32}
   },
   %Evision.Mat{
     channels: 2,
     dims: 2,
     raw_type: 12,
     ref: #Reference<0.791848197.4210950176.189007>,
     shape: {35, 1, 2},
     type: {:s, 32}
   },
   %Evision.Mat{
     channels: 2,
     dims: 2,
     raw_type: 12,
     ref: #Reference<0.791848197.4210950176.189008>,
     shape: {33, 1, 2},
     type: {:s, 32}
   },
   %Evision.Mat{
     channels: 2,
     dims: 2,
     raw_type: 12,
     ref: #Reference<0.791848197.4210950176.189009>,
     shape: {54, 1, 2},
     type: {:s, 32}
   },
   %Evision.Mat{
     channels: 2,
     dims: 2,
     raw_type: 12,
     ref: #Reference<0.791848197.4210950176.189010>,
     shape: {34, 1, 2},
     type: {:s, 32}
   },
   %Evision.Mat{
     channels: 2,
     dims: 2,
     raw_type: 12,
     ref: #Reference<0.791848197.4210950176.189011>,
     shape: {32, 1, 2},
     type: {:s, 32}
   },
   %Evision.Mat{
     channels: 2,
     dims: 2,
     raw_type: 12,
     ref: #Reference<0.791848197.4210950176.189012>,
     shape: {51, 1, 2},
     type: {:s, 32}
   },
   %Evision.Mat{
     channels: 2,
     dims: 2,
     raw_type: 12,
     ref: #Reference<0.791848197.4210950176.189013>,
     shape: {50, 1, 2},
     type: {:s, 32}
   },
   %Evision.Mat{
     channels: 2,
     dims: 2,
     raw_type: 12,
     ref: #Reference<0.791848197.4210950176.189014>,
     shape: {52, 1, 2},
     type: {:s, 32}
   },
   %Evision.Mat{
     channels: 2,
     dims: 2,
     raw_type: 12,
     ref: #Reference<0.791848197.4210950176.189015>,
     shape: {59, 1, ...},
     type: {:s, ...}
   },
   %Evision.Mat{
     channels: 2,
     dims: 2,
     raw_type: 12,
     ref: #Reference<0.791848197.4210950176.189016>,
     shape: {56, ...},
     type: {...}
   },
   %Evision.Mat{
     channels: 2,
     dims: 2,
     raw_type: 12,
     ref: #Reference<0.791848197.4210950176.189017>,
     shape: {...},
     ...
   },
   %Evision.Mat{
     channels: 2,
     dims: 2,
     raw_type: 12,
     ref: #Reference<0.791848197.4210950176.189018>,
     ...
   },
   %Evision.Mat{channels: 2, dims: 2, raw_type: 12, ...},
   %Evision.Mat{channels: 2, dims: 2, ...},
   %Evision.Mat{channels: 2, ...},
   %Evision.Mat{...},
   ...
 ],
 %Evision.Mat{
   channels: 4,
   dims: 2,
   raw_type: 28,
   ref: #Reference<0.791848197.4210950176.188973>,
   shape: {1, 80, 4},
   type: {:s, 32}
 }}

This was the final output i got after using find contours.
Can you please help me out with how can i apply pattern matching to this as I am very new to elixir.

If you have that value bound to a variable result you can do

{items, _} = result

items will be a list of things at that point.

P.S I made a small edit to your post to put the code in ` so that it formats more nicely.

1 Like

Thank you so much @benwilson512. I will try this to get the output and if I have any other issues I will get back to you.

Thank you once again.

did u got the output?