Próbuję znaleźć dane głębokości w określonym punkcie przechwyconego obrazu i zwrócić odległość w meters
.Jak odczytywać dane głębokości w punkcie CGPoint z bufora AVDepthData
Mam włączone dane głębokości i przechwytuję dane wraz z obrazem. Uzyskać punkt z X, Y współrzędne środka obrazu (i gdy naciśnięty) i jego konwersję do indeksu bufory stosując
Int((width - touchPoint.x) * (height - touchPoint.y))
z WIDTH
i HEIGHT
czym wymiary przechwyconego obrazu. Nie jestem pewien, czy jest to właściwa metoda, aby to osiągnąć.
obsłużyć dane takie jak głębokość:
func handlePhotoDepthCalculation(point : Int) {
guard let depth = self.photo else {
return
}
//
// Convert Disparity to Depth
//
let depthData = (depth.depthData as AVDepthData!).converting(toDepthDataType: kCVPixelFormatType_DepthFloat32)
let depthDataMap = depthData.depthDataMap //AVDepthData -> CVPixelBuffer
//
// Set Accuracy feedback
//
let accuracy = depthData.depthDataAccuracy
switch (accuracy) {
case .absolute:
/*
NOTE - Values within the depth map are absolutely
accurate within the physical world.
*/
self.accuracyLbl.text = "Absolute"
break
case .relative:
/*
NOTE - Values within the depth data map are usable for
foreground/background separation, but are not absolutely
accurate in the physical world. iPhone always produces this.
*/
self.accuracyLbl.text = "Relative"
}
//
// We convert the data
//
CVPixelBufferLockBaseAddress(depthDataMap, CVPixelBufferLockFlags(rawValue: 0))
let depthPointer = unsafeBitCast(CVPixelBufferGetBaseAddress(depthDataMap), to: UnsafeMutablePointer<Float32>.self)
//
// Get depth value for image center
//
let distanceAtXYPoint = depthPointer[point]
//
// Set UI
//
self.distanceLbl.text = "\(distanceAtXYPoint) m" //Returns distance in meters?
self.filteredLbl.text = "\(depthData.isDepthDataFiltered)"
}
nie jestem przekonany jestem coraz prawidłową pozycję. Z moich badań wynika również, że dokładność jest zwracana tylko w .relative
lub .absolute
, a nie float/integer?
Widziałem już pytanie, skąd skopiowałeś ten e-mail. Pokazałem również, jak uzyskać punkt danych - 'Int ((width - touchPoint.x) * (height - touchPoint.y)), który jest taki sam. To tylko opis problemu, a nie odpowiedź imo. – Allreadyhome