Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Fix input for unsigned char * #96

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions ImageSegmentation/ImageSegmentation/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,16 @@ class ViewController: UIViewController {
let w = Int32(resizedImage.size.width)
let h = Int32(resizedImage.size.height)
DispatchQueue.global().async {
let buffer = self.module.segment(image: UnsafeMutableRawPointer(&pixelBuffer), withWidth:w, withHeight: h)
let copiedBufferPtr = UnsafeMutablePointer<Float>.allocate(capacity: pixelBuffer.count)
copiedBufferPtr.initialize(from: pixelBuffer, count: pixelBuffer.count)
let buffer = self.module.segment(image: copiedBufferPtr, withWidth:w, withHeight: h)
copiedBufferPtr.deallocate()

let copiedOutputBufferPtr = UnsafeMutablePointer<CUnsignedChar>.allocate(capacity: Int(w * h * 3))
copiedOutputBufferPtr.initialize(from: buffer, count: Int(w * h * 3))

DispatchQueue.main.async {
self.imageView.image = self.imageHelper.convertRGBBuffer(toUIImage: buffer , withWidth: w, withHeight: h)
self.imageView.image = self.imageHelper.convertRGBBuffer(toUIImage: copiedOutputBufferPtr , withWidth: w, withHeight: h)
self.btnSegment.isEnabled = true
self.btnSegment.setTitle("Segment", for: .normal)
}
Expand Down