error: (-215:Assertion failed) (type == CV_32F || type == CV_8U) in function 'cv::batchDistance'
时间: 2024-01-25 13:04:12 浏览: 72
tensor_proto.raw_data().empty() || !tensor_proto.float_data().empty() || !tensor_proto.double_data()
This error typically occurs when using the OpenCV function cv::batchDistance with an input array that has a data type other than CV_32F (32-bit floating point) or CV_8U (8-bit unsigned integer). The function is designed to compute pairwise distances between two sets of vectors, and requires all vectors in the input arrays to be of the same data type.
To fix this error, make sure that the input arrays have a data type of CV_32F or CV_8U. You can use the cv::Mat::convertTo function to convert the data type of a cv::Mat object. For example, to convert an input array to 32-bit floating point:
```
cv::Mat input = ...; // input array
cv::Mat input_float;
input.convertTo(input_float, CV_32F); // convert to 32-bit floating point
cv::Mat distances;
cv::batchDistance(input_float, input_float, distances, ...); // compute pairwise distances
```
Alternatively, you can use the cv::normalize function to scale the input array to a range that is compatible with the batchDistance function. For example, to scale an input array to the range [0, 1]:
```
cv::Mat input = ...; // input array
cv::normalize(input, input, 0, 1, cv::NORM_MINMAX, CV_32F); // scale to [0, 1] and convert to 32-bit floating point
cv::Mat distances;
cv::batchDistance(input, input, distances, ...); // compute pairwise distances
```
阅读全文