Image dtype is printed differently across machines

I have a code that prints float32 for an image that I am processing on my local machine. However, the code does not work when we port it to another machine and it somehow prints the same image as float64. Why is that so? Is it because of the machine architecture, or OpenCV versions, or the numpy version?

Local machine:

print(image.dtype) : float32

Remote machine:

print(image.dtype) : float64

As a result of this, obviously, none of the image processing functions work in the code. What is the best way to overcome this?

EDIT: OpenCV version 4.5.5
OS: Ubuntu 20.04

Obviously, both machines run the same OS and have the same OpenCV versions.

Code:

normalized = np.ones_like(frame,dtype=np.float32)
edges = filters.sobel(normalized) # here it becomes float64
 edges = img_as_float32(edges) # required in some systems so that system does not throw float64/float32 in the next line
 gray = cv2.cvtColor(edges, cv2.COLOR_BGR2GRAY)

Error output:

...modules/imgproc/src/color.simd_helpers.hpp:94: error: (-2:Unspecified error) in function 'cv::impl::{anonymous}::CvtHelper<VScn, VDcn, VDepth, sizePolicy>::CvtHelper(cv::InputArray, cv::OutputArray, int) [with VScn = cv::impl::{anonymous}::Set<3, 4>; VDcn = cv::impl::{anonymous}::Set<1>; VDepth = cv::impl::{anonymous}::Set<0, 2, 5>; cv::impl::{anonymous}::SizePolicy sizePolicy = cv::impl::<unnamed>::NONE; cv::InputArray = const cv::_InputArray&; cv::OutputArray = const cv::_OutputArray&]'
> Unsupported depth of input image:
>     'VDepth::contains(depth)'
> where
>     'depth' is 6 (CV_64F)

please edit your question and add

  • opencv version
  • os
  • code that lead to the result above

more info please. what you’ve given so far is far from sufficient to even hypothesize.

you talk of architectures yet there’s no info on that at all. do you want us to think both machines run the same ubuntu and the same opencv version? what architectures are involved? who built OpenCV?

we still dont know, which code lead to the problem
please tell !

cvtColor does not support float64 images, no matter if ENABLE_FAST_MATH was set in cmake or not

but you’re reporting, that the type of edges changed. if this is a bug, it needs to be reported, right ?

try to be helpful, and show, how you generate / process the edges , please

OK, you were right. The reason why the code worked after I recompiled OpenCV was that the same setup file also re-installed Skimage, which was the actual problem.

 normalized = np.ones_like(frame,dtype=np.float32)
 kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (3,3))

    for i in range(3):
        normalized[:,:,i] = np.take(cumsum[i,:], frame[:,:,i]) / hist[i,:].sum()
    
    print("normalized:", normalized.dtype)
    edges = filters.sobel(normalized)
    print("edges:", edges.dtype)
    gray = cv2.cvtColor(edges, cv2.COLOR_BGR2GRAY)

output:

normalized: float32
edges: float64

So, it appears the function edges = filters.sobel(normalized) from Skimage caused the problem.

Those who faced this problem, although this is OpenCV forum and not Skimage one, here is how to solve it:

from skimage.util import img_as_float32
image = img_as_float32(any_opencv_image)

I also apologize on my own behalf. I removed the misleading posts, and I updated my original question so that it is a complete question now.