2012-10-25 3 views
0

3x3 행을 9x1로 정렬하는 방법을 생각하고 있습니다. 그래서행렬 정렬 및 행 하나에 배치

난 다음 한 :

enter image description here

내가이와 끝까지하려는 :

  Rect roi(y-1,x-1,kernel,kernel); 
      Mat image_roi = image(roi); 
      Mat image_sort(kernel, kernel, CV_8U); 
      cv::sort(image_roi, image_sort, CV_SORT_ASCENDING+CV_SORT_EVERY_ROW); 
:

enter image description here

이 내가 지금까지 일을 끝낼 것입니다

코드가 작동하지 않습니다. curre ntly 내 "sorted"후 내 image_sort에있는 데이터를 찾을 수 없습니다.

답변

3

물론 단일 채널 그레이 레벨 이미지가 있습니까? 시도 :

cv::Mat image_sort = cv::Mat::zeros(rect.height, rect.width, rect.type()); // allocated memory 
image(roi).copyTo(image_sort); // copy data in image_sorted 
std::sort(image_sort.data, image_sort.dataend); // call std::sort 
cv::Mat vectorized = image_sort.reshape(1, 1); // reshaped your WxH matrix into a 1x(W*H) vector.