Ask Your Question

Mat of int64

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

Naser gravatar image

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

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



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 -0600 )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 -0600 )edit

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 -0600 )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 -0600 )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 -0600 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2020-09-14 18:55:36 -0600

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*>([i] = *(static_cast<int64_t*>(tf_data) + i);
edit flag offensive delete link more

Question Tools

1 follower


Asked: 2020-09-04 17:45:05 -0600

Seen: 1,115 times

Last updated: Sep 05 '20