from C++ module How to pass C++ array in Gdscript
Asked Answered
C

3

0

Hi, i am new to Godot and i am trying to write a C++ module using OpenCV for displaying video or webcam in Godot

i create a class to handle get video frame, for example getFrame()

for getFrame(), cv::Mat will be returned but i think cv::Mat can not be used in gdscript so i wan to ask how can i wrap or convert the pixel data(c++ array) of cv::Mat into the data type used in gdscript ?

i will appreciated it if you can point me out how to do it or what document i can read?

Thanks

Cartie answered 26/5, 2021 at 13:40 Comment(0)
S
0

I'm not sure but I think that if doing a function that returns the array should work, but what I don't know is if you will have to convert it to a godot array or it can be a normal array

Array new_array = [];  // godot array

for (i = 0; i <= you_array.length(); i++) {
		new_array.append(you_array[i]);
}

return new_array;

that's what occurs to me if only godot arrays can be returned

maybe with this idea you can come up with something better than this

Sublimation answered 27/5, 2021 at 17:48 Comment(0)
V
0

@kyushu said: i will appreciated it if you can point me out how to do it or what document i can read?

I'd recommend reading header files: https://github.com/godotengine/godot-cpp/blob/b400dba87534640eeddbcdb6b319335a6a7639d8/include/core/Array.hpp#L57-L157

Looking at this file, I'd guess you need to 1) create a new Array object, and then go over your OpenCV data and 2) append items to the Godot Array.

Note that items are often typed as Variant, those are just wrappers around actual classes to have some kind of runtime reflection. Meaning you can append other arrays too, in case you are dealing with 2d arrays.

Vickyvico answered 28/5, 2021 at 1:42 Comment(0)
R
0

I don't know if I can answer your question exactly, but you can convert cv::Mat to a Godot image:
How to convert cv::Mat to Godot Image?

Other resources you can benefit from:
Trying to link a .so file in SCsub
Get frames from the camera (Java)
Bouncy - Godot OpenCV integration example

Romans answered 21/2, 2024 at 12:55 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.