Alenorze
@Alenorze
Не люблю Индию

Как перевести этот код Python на C++?

mask = np.uint8(mask_crop)  - изображение после threshold

cnts = cv2.findContours(mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)[-2]
cnt = sorted(cnts, key=cv2.contourArea)[-1]

x,y,w,h = cv2.boundingRect(cnt)

if h * 1.2 <= w:
    h = int(h * 1.8)
elif h <= w:
    h = int(h * 1.3)
elif h * 0.8 <= w:
    h = int(h * 1.3)

mask_hard = mask_hard[y:y+h, x:x+w]
img_rgba = image_with_alpha[y:y+h, x:x+w]
img_lab = cv2.cvtColor(image[y:y+h, x:x+w], cv2.COLOR_RGB2LAB)
img_mean, img_std = cv2.meanStdDev(img_lab, mask=mask_hard.astype(np.uint8))


Вот что у меня пока получилось
cv::cuda::GpuMat image_mask_input_hard(image_mask); 
 cv::cuda::GpuMat mask_hard; 
 cv::cuda::threshold(image_mask_input_hard, mask_hard, 0.5, 1.0, THRESH_BINARY); - изображение после threshold
    
 cv::cuda::GpuMat cnts; 
 vector<vector<Point>> contours;
 vector<Vec4i> hierarchy;
 cv::cuda::findContours(cnts, contours, hierarchy, RETR_TREE, CHAIN_APPROX_SIMPLE, Point(0, 0));
    // cnt = sorted(cnts, key=cv2.contourArea)[-1]


Хотелось бы все реализовать с cuda, сам в C++ не разбираюсь, заранее спасибо за любую помощь.
  • Вопрос задан
  • 184 просмотра
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы