In a playground now, I have the following code
Code Block let context = CIContext() |
| let orginalImage = UIImage.init(named: imageArray[0]) |
|
|
|
| let inputImage = CIImage.init(cgImage: (orginalImage?.cgImage)!) |
|
| let contourRequest = VNDetectContoursRequest.init() |
|
| contourRequest.detectDarkOnLight = true |
|
| contourRequest.contrastAdjustment = 1.0 |
|
|
|
| let areaOfIntrest = CGRect(x: 0, y: 0, width: 50, height: 50) |
|
| let roi = VNNormalizedRectForImageRect(areaOfIntrest, 3264, 2448) |
|
| contourRequest.regionOfInterest = roi |
|
|
|
|
|
| let requestHandler = VNImageRequestHandler(cgImage: (orginalImage?.cgImage)!, options: [:]) |
|
| do{ |
|
| try requestHandler.perform([contourRequest]) |
|
| }catch{ |
|
| print("error in perform") |
|
| } |
|
| let observations = contourRequest.results?.first as! VNContoursObservation |
|
| print(observations.contourCount) |
|
| let imageContours = drawContours(contoursObservation: observations, sourceImage: (orginalImage?.cgImage)!) |
|
|
|
| print(imageContours.size) |
But I still get contours that our outside of the Region of Interest. Which I would think would be a rectangle that his 50 x 50 and starts in the lower left corner. Am I misunderstanding how the region of interest works.