Error while using Sobel edge detection method

Solution for Error while using Sobel edge detection method
is Given Below:

img = cv2.imread('skeleton.JPG')

gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)


sobelx = cv2.Sobel(gray, cv2.CV_64F, 1, 0,ksize=5)
sobely = cv2.Sobel(gray, cv2.CV_64F, 0, 1,ksize=5)

plt.imshow(cv2.cvtColor(sobelx, cv2.COLOR_BGR2RGB))

I’m getting error as follows,

error                                     Traceback (most recent call last)
<ipython-input-51-3e640684ed0a> in <module>
----> 1 plt.imshow(cv2.cvtColor(sobelx, cv2.COLOR_BGR2RGB))

error: OpenCV(4.2.0) c:projectsopencv-pythonopencvmodulesimgprocsrccolor.simd_helpers.hpp:94: error: (-2:Unspecified error) in function '__cdecl cv::impl::`anonymous-namespace'::CvtHelper<struct cv::impl::`anonymous namespace'::Set<1,-1,-1>,struct cv::impl::A0xe227985e::Set<3,4,-1>,struct cv::impl::A0xe227985e::Set<0,2,5>,2>::CvtHelper(const class cv::_InputArray &,const class cv::_OutputArray &,int)'
> Unsupported depth of input image:
>     'VDepth::contains(depth)'
> where
>     'depth' is 6 (CV_64F)

In the Sobel operation, after computing sobelx and sobely you have to compute np.sqrt(sobelx ** 2 + sobely ** 2). After that you should choose a threshold to find edges. Moreover, you will get a black and white image, so you can’t convert it to RGB or BGR image.
The right code will be:

import cv2
import matplotlib.pyplot as plt
import numpy as np

threshold = 6.

img = cv2.imread('skeleton.JPG')

gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) / 255

sobelx = cv2.Sobel(gray, cv2.CV_64F, 1, 0, ksize=5)
sobely = cv2.Sobel(gray, cv2.CV_64F, 0, 1, ksize=5)
sobel_xy = np.sqrt(sobelx ** 2 + sobely ** 2)
edge_image = np.float32(sobel_xy > threshold)

plt.imshow(edge_image, 'gray')
plt.show()

If you want to display sobelx you can apply np.abs and normalize it and then show:

sobelx_disp = np.abs(sobelx)
sobelx_disp = sobelx_disp / np.max(sobelx_disp)
plt.imshow(sobelx_disp, 'gray')
plt.show()