【error: Unknown C++ exception from OpenCV code】

Project scenario:

Segmentation of remote sensing images through the kmeans module of opencv


Problem Description

error: Unknown C++ exception from OpenCV code

c = (cv.TERM_CRITERIA_EPS+ cv.TERM_CRITERIA_MAX_ITER,10, 0.1)
k=2
ret, label, center = cv.kmeans(image, k, None, c, 10, cv.KMEANS_RANDOM_CENTERS)

Cause Analysis:

Some say that the version of opencv is too high and the version of python is low. I thought it would be too troublesome to change the version, so I didn't try it. So I checked the information about opencv and found insert image description here
that when the data to be processed must occupy one row per element, I am clustering a single feature here, so the shape of my data should be n rows and one column, and n is like the number of elements.


solution:

Add this code before executing kmeans: image_1 = image.reshape((image.shape[0]*image.shape[1],1))

Guess you like

Origin blog.csdn.net/m0_46403007/article/details/124255092