如何在Objective C ++中复制此代码(Python)?

时间:2019-08-25 21:22:45

标签: python swift opencv objective-c++

我正在开发这个使用OpenCV的Harris Corner的Swift项目。由于语言不同,我将使用Objective C ++作为中介语言。我正在学习本教程,但是现在我无法在Objective C ++中复制一行代码(Python)。

filename = 'chessboard.jpg'
img = cv2.imread(filename)
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

gray = np.float32(gray)
dst = cv2.cornerHarris(gray,2,3,0.04)

#result is dilated for marking the corners, not important
dst = cv2.dilate(dst,None)

# Threshold for an optimal value, it may vary depending on the image.
**img[dst>0.01*dst.max()]=[0,0,255]** //This is the line I don't know how to write in Objective C++

目前,我有这段代码,除了最后一行:

+ (NSArray<NSArray<NSNumber *> *> *)harrisonCorners:(UIImage *)image {
    cv::Mat mat;
    [image convertToMat: &mat];

    cv::Mat gray, corner, dst;
    if (mat.channels() > 1) {
        cv::cvtColor(mat, gray, CV_RGB2GRAY);
    } else {
        mat.copyTo(gray);
    }

    cv::cornerHarris(gray, corner, 2, 3, 0.04);

    //The line of code should be here

    return nil;//Return a 2D array with the corners
}

任何帮助将不胜感激。

谢谢

0 个答案:

没有答案