A
A
Alexey Belov2019-05-30 16:20:36
C++ / C#
Alexey Belov, 2019-05-30 16:20:36

How to translate this Python code to 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))

Here's what I've got so far
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]

I would like to implement everything with cuda, I don’t understand C ++ myself, thanks in advance for any help.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question