Mat of int64

asked 2020-09-04 17:45:05 -0500

Naser gravatar image

updated 2020-09-05 03:23:08 -0500

Hellow everybody. I have an array of tensorflow::int64 numbers like this :

tensorflow::int64 data[10] = {1,2,3,4,5,7,8,9,10,11}

now i want to initialize a Mat with this array , but opencv doesn't support CV_64SC1 or int64 datatype. can anybody help me how can create a Mat of int64 datatype and initialize it with this array ? Thank you in advance.

edit retag flag offensive close merge delete

Comments

2

At present there is no CV_64S support, so your best option is to convert/cast to CV_32S for down stream processing.

Der Luftmensch gravatar imageDer Luftmensch ( 2020-09-05 09:22:39 -0500 )edit

@Der Luftmensch thanks for your answer and sorry for delay in my answer. Casting in tensorflow takes a while and i can't precess my video in relatime. I'm wondering to create a Mat of int64 type . Do you have any idea about that ?

Naser gravatar imageNaser ( 2020-09-14 13:16:34 -0500 )edit
1

As I said above, there is no int64 support in cv::Mat. Have you measured the performance costs of casting to int32? It might be significantly smaller than you think, modern compilers are great at vectorizing.

Der Luftmensch gravatar imageDer Luftmensch ( 2020-09-14 14:35:22 -0500 )edit

Yes i tested casting in tensorflow c++ api and it reduces process speed significantly. My original array is a pointer of a tensor values , so tried casting with reinterpret_cast as an other solution , but it didn't give me a correct answer. I can bring you my code if you want.

Naser gravatar imageNaser ( 2020-09-14 16:19:05 -0500 )edit
1

Try something similar to the following:

//
// This is a deep copy, OpenCV has no CV_64(U|S) types, only CV_32S:
//
cv::Mat mat_32(size, CV_32SC(c));
for (size_t i = 0; i < image_elements; ++i) {
    reinterpret_cast<int32_t*>(mat_32.data)[i] = *(static_cast<int64_t*>(tf_data) + i);
}
Der Luftmensch gravatar imageDer Luftmensch ( 2020-09-14 18:55:36 -0500 )edit

@Der Luftmensch Yes , this is actually what is needed , i got the correct answer, Thank you so much sir.

Naser gravatar imageNaser ( 2020-09-15 02:34:37 -0500 )edit