yeatse / opencv-spm

Integrate OpenCV into your project using Swift Package Manager.
Apache License 2.0
75 stars 23 forks source link

[question]laplacian function available? #4

Closed junmcenroe closed 1 year ago

junmcenroe commented 1 year ago

Dear yeatse

I successfully install the opencv-spm in my iOS project. I want to measure blurr of image, so like following laplacian = cv2.Laplacian(gray, cv2.CV_64F)

I cannot find the likely command under Imgproc.

Can I measure blurr with this package?

yeatse commented 1 year ago

According to the documentation, you need to include <opencv2/imgproc.hpp> in order to use laplacian in c++. In Swift, you can call Imgproc.Laplacian instead. For example: Imgproc.Laplacian(src: gray, dst: result, ddepth: CvType.CV_64F).

junmcenroe commented 1 year ago

Dear yeatse

Thanks for your advice. I tried following code (Sorry cannot copy&Past with correct indent)

let src = Mat(uiImage: UIImage(named: "cat0")!) // Transform source image to gray if it is not already let gray: Mat if (src.channels() == 3) { gray = Mat() Imgproc.cvtColor(src: src, dst: gray, code: .COLOR_BGR2GRAY) } else { gray = src } let out = Mat() let laplacian: Void = Imgproc.Laplacian(src: gray, dst: out, ddepth: CvType.CV_64F) print("Laplacian value2: (laplacian)")

But print result (). Because Xcode forced me set Void to use Imgproc.Laplacian call

What wrong? I just installed your spm with your procedure, not additional header such as <opencv2/imgproc.hpp>

Any advice?

yeatse commented 1 year ago

In C++, this function does not return a value. Instead, the result is stored in the out parameter. For further details, please refer the documentation:

image
junmcenroe commented 1 year ago

Dear yeatse

When I use OpenCV on Python, I can get the value with ** import cv2

laplacian = cv2.Laplacian(gray, cv2.CV_64F) print("laplacian.var() value?",laplacian.var()) if laplacian.var() < 100: text = "Blurry" else: text = "Not Blurry" ** But Dit C++, Swift not support this?

yeatse commented 1 year ago

You can ask ChatGPT or New Bing

image

The equivalent of meanStdDev in Swift is Core.meanStdDev.