34 if (ARWorldTrackingConfiguration.isSupported)
44 _arConfig = [ARWorldTrackingConfiguration new];
51 _arConfig.videoFormat = ARWorldTrackingConfiguration.supportedVideoFormats.lastObject;
53 _arConfig.worldAlignment = ARWorldAlignmentGravity;
59 return ARWorldTrackingConfiguration.isSupported;
64 if (ARWorldTrackingConfiguration.isSupported &&
_arSession)
66 [_arSession runWithConfiguration:_arConfig];
83 if (ARWorldTrackingConfiguration.isSupported &&
_arSession)
85 [_arSession runWithConfiguration:_arConfig options:ARSessionRunOptionResetTracking | ARSessionRunOptionRemoveExistingAnchors];
92 - (
void)latestFrame:(cv::Mat*)pose
93 withImg:(cv::Mat*)imgBGR
94 AndIntrinsic:(cv::Mat*)intrinsic
97 IsTracking:(BOOL*)isTracking
98 WithPointClout:(cv::Mat*)pc
104 Utils::log(
"SENSiOSARCoreDelegate",
"frame is invalid");
108 ARCamera* camera = frame.camera;
111 *pose = cv::Mat_<float>(4, 4);
112 for (
int i = 0; i < 4; ++i)
114 simd_float4 col = camera.transform.columns[i];
115 pose->at<
float>(0, i) = (
float)col[0];
116 pose->at<
float>(1, i) = (
float)col[1];
117 pose->at<
float>(2, i) = (
float)col[2];
118 pose->at<
float>(3, i) = (
float)col[3];
122 *intrinsic = cv::Mat_<double>(3, 3);
123 for (
int i = 0; i < 3; ++i)
125 simd_float3 col = camera.intrinsics.columns[i];
126 intrinsic->at<
double>(0, i) = (
double)col[0];
127 intrinsic->at<
double>(1, i) = (
double)col[1];
128 intrinsic->at<
double>(2, i) = (
double)col[2];
131 if (frame.camera.trackingState == ARTrackingStateNormal)
137 CVImageBufferRef pixelBuffer = frame.capturedImage;
139 CVReturn ret = CVPixelBufferLockBaseAddress(pixelBuffer, kCVPixelBufferLock_ReadOnly);
142 if (ret == kCVReturnSuccess)
144 OSType pixelFormat = CVPixelBufferGetPixelFormatType(pixelBuffer);
145 if (pixelFormat == kCVPixelFormatType_420YpCbCr8BiPlanarFullRange)
147 size_t imgWidth = CVPixelBufferGetWidth(pixelBuffer);
148 size_t imgHeight = CVPixelBufferGetHeight(pixelBuffer);
152 uint8_t* yPlane = (uint8_t*)CVPixelBufferGetBaseAddressOfPlane(pixelBuffer, 0);
154 cv::Mat yuvImg((
int)imgHeight + ((
int)imgHeight / 2), (
int)imgWidth, CV_8UC1, yPlane);
155 cv::cvtColor(yuvImg, *imgBGR, cv::COLOR_YUV2BGR_NV12, 3);
158 if (ret != kCVReturnSuccess)
160 Utils::log(
"SENSiOSARCoreDelegate",
"pixelbuffer not locked");
162 CVPixelBufferUnlockBaseAddress(pixelBuffer, kCVPixelBufferLock_ReadOnly);
167 ARPointCloud* rawFPts = [frame rawFeaturePoints];
171 *pc = cv::Mat((
int)rawFPts.count, 4, CV_32F);
172 memcpy(pc->data, rawFPts.points, rawFPts.count *
sizeof(simd_float3));
177 #pragma mark - ARSessionDelegate
179 - (
void)session:(ARSession*)session didFailWithError:(NSError*)error
184 - (
void)session:(ARSession*)session cameraDidChangeTrackingState:(ARCamera*)camera
186 switch (camera.trackingState)
188 case ARTrackingStateNormal:
189 NSLog(
@"Tracking is Normal.\n");
191 case ARTrackingStateLimited:
192 NSLog(
@"Tracking is limited: ");
193 switch (camera.trackingStateReason)
195 case ARTrackingStateReasonNone:
196 NSLog(
@"Tracking is not limited.\n");
198 case ARTrackingStateReasonInitializing:
199 NSLog(
@"Tracking is limited due to initialization in progress.\n");
201 case ARTrackingStateReasonExcessiveMotion:
202 NSLog(
@"Tracking is limited due to a excessive motion of the camera.\n");
204 case ARTrackingStateReasonInsufficientFeatures:
205 NSLog(
@"Tracking is limited due to a lack of features visible to the camera.\n");
207 case ARTrackingStateReasonRelocalizing:
208 NSLog(
@"Tracking is limited due to a relocalization in progress.\n");
214 case ARTrackingStateNotAvailable:
215 NSLog(
@"Tracking is not available.\n");
222 - (
void)sessionWasInterrupted:(ARSession*)session
224 NSLog(
@"sessionInterruptionEnded.\n");
228 - (
void)sessionInterruptionEnded:(ARSession*)session
230 NSLog(
@"sessionInterruptionEnded.\n");
typedef void(SL_STDCALL *cbOnImGuiBuild)(SLScene *s
Callback function typedef for ImGui build function.
ARConfiguration * _arConfig
int run(Config config)
App::run implementation from App.h for the Emscripten platform.
void log(const char *tag, const char *format,...)
logs a formatted string platform independently