Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to read JSON files using OpenCV FileStorage with C++ Program

I'm new to OpenCV and also C++ Programming. I have multiple JSON files and have read each file and store the values in vectors or arrays. I'm not sure which is best way store the values, since json file has huge number of comma separated values and need to store each value in three parameter structure.

Example JSON file, image description

I have t oread only val1 using json and the json file may have multiple entries of val1. I have to read all val1 values and store it an array/vector. After reading val1, have to store combination of three values in three parameter structure. So, val1 itself will be stored in an array of structures and second val1 also should store in another continuous array of structure. And each file should store in continuous array of structure.

Expected results as follows, val1 : 516.85,444.377,0.859822,539.18,466.636,0.790611,477.802,455.542,0.847968,366.262,461.046,0.805154,321.499,410.842,0.783296

struct a { float a, float b, float c }

struct a arr[][];

arr[0][0] = {a=516.85, b = 444.377, c=0.859822} arr[0][1] = {a=539.18, b=466.636, c=0.790611}

val2 : 0,0,0,0,0,0,1125.33,586.703,0.0834661 arr[1][0] = {a=0. b=0, c=0} arr[1][1] = {a=0, b=0, c=0} arr[1][2] = {a=1125.33, b=586.703, =0.0834661}

Please let me know if any solution available.

Thanks in advance.

How to read JSON files using OpenCV FileStorage with C++ Program

I'm new to OpenCV and also C++ Programming. I have multiple JSON files and have read each file and store the values in vectors or arrays. I'm not sure which is best way store the values, since json file has huge number of comma separated values and need to store each value in three parameter structure.

Example JSON file, image description

file,

{
    "version":1.0,
    "points":[
        {
            "val1":[
                516.85,444.377,0.859822,539.18,466.636,0.790611,477.802,455.542,0.847968,366.262,461.046,0.805154,321.499,410.842,0.783296
            ],
            "val2":[

            ]

        },
        {
            "val1":[
                0,0,0,0,0,0,1125.33,586.703,0.0834661,1013.77,589.487,0.311553,924.413,597.834,0.348648
            ],
            "val2":[

            ]
        }
    ]
}

I have t oread only val1 using json and the json file may have multiple entries of val1. I have to read all val1 values and store it an array/vector. After reading val1, have to store combination of three values in three parameter structure. So, val1 itself will be stored in an array of structures and second val1 also should store in another continuous array of structure. And each file should store in continuous array of structure.

Expected results as follows, val1 : 516.85,444.377,0.859822,539.18,466.636,0.790611,477.802,455.542,0.847968,366.262,461.046,0.805154,321.499,410.842,0.783296

struct a { float a, float b, float c }

struct a arr[][];

arr[0][0] = {a=516.85, b = 444.377, c=0.859822} arr[0][1] = {a=539.18, b=466.636, c=0.790611}

val2 : 0,0,0,0,0,0,1125.33,586.703,0.0834661 arr[1][0] = {a=0. b=0, c=0} arr[1][1] = {a=0, b=0, c=0} arr[1][2] = {a=1125.33, b=586.703, =0.0834661}

Please let me know if any solution available.

Thanks in advance.