import cv2 traing, traintheta = cv2.cartToPolar(trainsobelx, trainsobely) testg,…
- User
import cv2
train_g, train_theta = cv2.cartToPolar(train_sobel_x, train_sobel_y) test_g, test_theta = cv2.cartToPolar(test_sobel_x, test_sobel_y) error: OpenCV(4.8.0) /io/opencv/modules/core/src/mathfuncs.cpp:281: error: (-215:Assertion failed) X.size == Y.size && type == Y.type() && (depth == CV_32F || depth == CV_64F) in function 'cartToPolar'
- Assistant
It seems that the error is occurring because the size of the input arrays
train_sobel_x,train_sobel_y,test_sobel_x, andtest_sobel_yare not matching. Make sure that the size of these arrays is the same before passing them to thecv2.cartToPolarfunction. Additionally, ensure that the data type of the arrays is eitherCV_32ForCV_64F.You can check the sizes and data types of the input arrays using the
shapeanddtypeattributes of the NumPy arrays. Make sure to resize or reshape the arrays if needed to match their sizes before passing them tocv2.cartToPolar. - User
а по русски?
- Assistant
Похоже, что ошибка возникает из-за того, что размеры входных массивов
train_sobel_x,train_sobel_y,test_sobel_xиtest_sobel_yне совпадают. Убедитесь, что размер этих массивов одинаковый перед передачей их в функциюcv2.cartToPolar. Кроме того, убедитесь, что тип данных массивов либоCV_32F, либоCV_64F.Вы можете проверить размеры и типы данных входных массивов, используя атрибуты
shapeиdtypeмассивов NumPy. Убедитесь, что размеры массивов совпадают перед передачей их в функциюcv2.cartToPolar. В случае необходимости измените размер или форму массивов, чтобы они соответствовали друг другу перед передачей их вcv2.cartToPolar. - User
train_sobel_y.shape имеет размерность (60000, 28, 28) как и train_sobel_x.shape
- Assistant
Если размерности массивов
train_sobel_xиtrain_sobel_yравны (60000, 28, 28), то причина ошибки скорее всего в типе данных. Убедитесь, что тип данных этих массивов является либоCV_32F, либоCV_64F.Если данные массивы не имеют правильного типа данных, вы можете преобразовать их к нужному типу, используя метод
.astype()в библиотеке NumPy перед вызовом функцииcv2.cartToPolar. Например:train_sobel_x = train_sobel_x.astype(np.float32) train_sobel_y = train_sobel_y.astype(np.float32) test_sobel_x = test_sobel_x.astype(np.float32) test_sobel_y = test_sobel_y.astype(np.float32) train_g, train_theta = cv2.cartToPolar(train_sobel_x, train_sobel_y) test_g, test_theta = cv2.cartToPolar(test_sobel_x, test_sobel_y)Это приведет ваши массивы к типу
float32перед передачей их в функциюcv2.cartToPolar, что, вероятно, устранило бы ошибку.