Skip to content

Commit b02139c

Browse files
feat: update to arcore 1.51.0, fix AR Markers Android
1 parent 3d1cb9c commit b02139c

File tree

18 files changed

+188
-98
lines changed

18 files changed

+188
-98
lines changed

β€Žandroid/libs/arcore/include/arcore_c_api.hβ€Ž

Lines changed: 106 additions & 64 deletions
Large diffs are not rendered by default.

β€Žandroid/memoryleaktest/build.gradleβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ dependencies {
6464
androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1'
6565
implementation project(':virocore')
6666
implementation project(':libs:gvr')
67-
implementation 'com.google.ar:core:1.45.0'
67+
implementation 'com.google.ar:core:1.41.0'
6868
implementation "androidx.appcompat:appcompat:1.0.0"
6969
implementation "androidx.core:core-ktx:1.8.0"
7070
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:2.0.20"

β€Žandroid/nativetest/build.gradleβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ android {
6565

6666
dependencies {
6767
implementation fileTree(include: ['*.jar'], dir: 'libs')
68-
implementation 'com.google.ar:core:1.45.0'
68+
implementation 'com.google.ar:core:1.51.0'
6969
implementation project(':libs:gvr')
7070
implementation project(':virocore')
7171
implementation "androidx.appcompat:appcompat:1.0.0"

β€Žandroid/releasetest/build.gradleβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ dependencies {
8383
implementation fileTree(include: ['*.jar'], dir: 'libs')
8484
androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1'
8585
implementation project(':virocore')
86-
implementation 'com.google.ar:core:1.45.0'
86+
implementation 'com.google.ar:core:1.51.0'
8787
implementation project(':libs:gvr')
8888
implementation "androidx.appcompat:appcompat:1.0.0"
8989
// testing dependencies

β€Žandroid/renderertest/build.gradleβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ android {
6666

6767
dependencies {
6868
implementation fileTree(include: ['*.jar'], dir: 'libs')
69-
implementation 'com.google.ar:core:1.45.0'
69+
implementation 'com.google.ar:core:1.51.0'
7070
implementation project(':libs:gvr')
7171
implementation project(':virocore')
7272
implementation "androidx.appcompat:appcompat:1.0.0"

β€Žandroid/sharedCode/build.gradleβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ dependencies {
4646
implementation 'androidx.media3:media3-exoplayer-hls:1.1.1'
4747
implementation 'androidx.media3:media3-exoplayer-smoothstreaming:1.1.1'
4848
implementation project(':libs:gvr')
49-
implementation 'com.google.ar:core:1.45.0'
49+
implementation 'com.google.ar:core:1.51.0'
5050
implementation 'com.google.protobuf.nano:protobuf-javanano:3.0.0-alpha-7'
5151
implementation "androidx.core:core-ktx:1.8.0"
5252
implementation "org.jetbrains.kotlin:kotlin-stdlib:2.0.0"

β€Žandroid/sharedCode/src/main/cpp/VROImageAndroid.cppβ€Ž

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,17 @@ unsigned char *VROImageAndroid::getData(size_t *length) {
9696
This function is used by VROARImageTargetAndroid (w/ ARCore). As such, we can
9797
make a few assumptions, that the data is from a Bitmap and is using the RGBA_8888
9898
format.
99+
100+
IMPORTANT: ARCore requires stride == width for augmented images. We always
101+
return a tightly-packed grayscale buffer.
99102
*/
100103
unsigned char *VROImageAndroid::getGrayscaleData(size_t *length, size_t *stride) {
101-
*length = _dataLength / 4; // the length is 1/4th because RGBA -> Grayscale (1 byte)
104+
*length = _width * _height; // tightly-packed grayscale (no padding)
105+
*stride = _width; // ARCore requires stride == width
102106

103107
if (_grayscaleData == nullptr) {
104-
// we can make this assumption because VROPlatformConvertBitmap computes _dataLength = _stride * _height
108+
// Calculate the RGBA stride from the original data
105109
int32_t rgbastride = _dataLength / _height;
106-
*stride = rgbastride / 4;
107-
108110
convertRgbaToGrayscale(rgbastride, &_grayscaleData);
109111
}
110112
return _grayscaleData;
@@ -113,17 +115,22 @@ unsigned char *VROImageAndroid::getGrayscaleData(size_t *length, size_t *stride)
113115
/*
114116
This function comes from the augmented_image_c example provided by ARCore (util.h's
115117
ConvertRgbaToGrayscale function).
118+
119+
IMPORTANT: ARCore requires stride == width for augmented images. We always
120+
output a tightly-packed grayscale buffer (no row padding) regardless of the
121+
input RGBA stride.
116122
*/
117123
void VROImageAndroid::convertRgbaToGrayscale(int32_t stride, uint8_t **out_grayscale_buffer) {
118-
int32_t grayscale_stride = stride / 4; // Only support RGBA_8888 format
119-
uint8_t *grayscale_buffer = new uint8_t[grayscale_stride * _height];
124+
// Always use width as the output stride (no padding) - ARCore requires stride == width
125+
uint8_t *grayscale_buffer = new uint8_t[_width * _height];
120126
for (int h = 0; h < _height; ++h) {
121127
for (int w = 0; w < _width; ++w) {
122128
const uint8_t *pixel = &_data[w * 4 + h * stride];
123129
uint8_t r = *pixel;
124130
uint8_t g = *(pixel + 1);
125131
uint8_t b = *(pixel + 2);
126-
grayscale_buffer[w + h * grayscale_stride] =
132+
// Write to tightly-packed buffer (stride == width)
133+
grayscale_buffer[w + h * _width] =
127134
static_cast<uint8_t>(0.213f * r + 0.715 * g + 0.072 * b);
128135
}
129136
}

β€Žandroid/sharedCode/src/main/cpp/arcore/ARCore_API.hβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ namespace arcore {
320320
FocusMode focusMode, DepthMode depthMode, SemanticMode semanticMode) = 0;
321321

322322
virtual bool isDepthModeSupported(DepthMode depthMode) = 0;
323+
virtual bool isSemanticModeSupported(SemanticMode semanticMode) = 0;
323324

324325
virtual AugmentedImageDatabase *createAugmentedImageDatabase() = 0;
325326
virtual AugmentedImageDatabase *createAugmentedImageDatabase(uint8_t* raw_buffer, int64_t size) = 0;

β€Žandroid/sharedCode/src/main/cpp/arcore/VROARSessionARCore.cppβ€Ž

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -284,36 +284,37 @@ bool VROARSessionARCore::updateARCoreConfig() {
284284
}
285285
}
286286

287-
pinfo("Creating ARCore config with planeFindingMode=%d, depthMode=%d, semanticMode=%d",
288-
(int)_planeFindingMode, (int)effectiveDepthMode, (int)_semanticMode); // DEBUG
287+
// Check if semantic mode is supported on this device
288+
arcore::SemanticMode effectiveSemanticMode = _semanticMode;
289+
if (_semanticMode != arcore::SemanticMode::Disabled) {
290+
if (!_session->isSemanticModeSupported(_semanticMode)) {
291+
pwarn("⚠️ Requested semantic mode %d not supported on this device, falling back to DISABLED",
292+
(int)_semanticMode);
293+
effectiveSemanticMode = arcore::SemanticMode::Disabled;
294+
}
295+
}
296+
289297
arcore::Config *config =
290298
_session->createConfig(_lightingMode, _planeFindingMode, _updateMode,
291-
_cloudAnchorMode, _focusMode, effectiveDepthMode, _semanticMode);
299+
_cloudAnchorMode, _focusMode, effectiveDepthMode, effectiveSemanticMode);
292300

293301
if (getImageTrackingImpl() == VROImageTrackingImpl::ARCore &&
294302
_currentARCoreImageDatabase) {
295303
config->setAugmentedImageDatabase(_currentARCoreImageDatabase);
296304
}
297305

298-
pinfo("Applying config to ARCore session..."); // DEBUG
306+
// ARCore requires the session to be paused before calling configure()
307+
_session->pause();
308+
299309
arcore::ConfigStatus status = _session->configure(config);
300310
delete (config);
301311

302312
if (status == arcore::ConfigStatus::Success) {
303-
pinfo("βœ… Successfully configured AR session [lighting %d, planes %d, "
304-
"update %d, focus %d, depth %d, semantic %d]",
305-
_lightingMode, _planeFindingMode, _updateMode, _focusMode, effectiveDepthMode, _semanticMode);
306313
_session->resume();
307314
return true;
308-
} else if (status == arcore::ConfigStatus::UnsupportedConfiguration) {
309-
pwarn("❌ Failed to configure AR session: configuration not supported");
310-
pwarn(" Your device may not support the requested features (vertical planes, depth, or semantic mode)!");
311-
return false;
312-
} else if (status == arcore::ConfigStatus::SessionNotPaused) {
313-
pwarn("❌ Failed to change AR configuration: session must be paused");
314-
return false;
315315
} else {
316-
pwarn("❌ Unknown error updating AR configuration");
316+
pwarn("Failed to configure AR session (status %d)", (int)status);
317+
_session->resume();
317318
return false;
318319
}
319320
}
@@ -498,7 +499,7 @@ void VROARSessionARCore::addTargetToDatabase(
498499
rotateImageForOrientation(&grayscaleImage, &width, &height, &stride,
499500
target->getOrientation());
500501

501-
database->addImageWithPhysicalSize(
502+
arcore::AugmentedImageDatabaseStatus status = database->addImageWithPhysicalSize(
502503
targetAndroid->getId().c_str(), grayscaleImage, width, height,
503504
(int32_t)stride, target->getPhysicalWidth(), &outIndex);
504505

@@ -918,7 +919,6 @@ void VROARSessionARCore::processUpdatedAnchors(VROARFrameARCore *frameAR) {
918919
arcore::TrackableList *imageList = _session->createTrackableList();
919920
frame->getUpdatedTrackables(imageList, arcore::TrackableType::Image);
920921
int imageSize = imageList->size();
921-
922922
for (int i = 0; i < imageSize; i++) {
923923
arcore::Trackable *trackable = imageList->acquireItem(i);
924924
arcore::AugmentedImage *image = (arcore::AugmentedImage *)trackable;
@@ -968,8 +968,6 @@ void VROARSessionARCore::processUpdatedAnchors(VROARFrameARCore *frameAR) {
968968
target = std::dynamic_pointer_cast<VROARImageTargetAndroid>(
969969
_imageTargets[j]);
970970
if (key == target->getId()) {
971-
pinfo("Detected new anchor tied to image target [%s]",
972-
key.c_str());
973971
haveFoundTarget = true;
974972
// break out of the loop since we found a target id that matches
975973
// the key

β€Žandroid/sharedCode/src/main/java/com/viro/core/ARImageTarget.javaβ€Ž

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,27 @@ public long getNativeRef() {
129129
* <i>post</i>-orientation.
130130
*/
131131
public ARImageTarget(Bitmap image, Orientation orientation, float physicalWidth) {
132-
mId = String.valueOf(this.hashCode()); // the ID is simply the string of the hashCode().
132+
this(image, orientation, physicalWidth, null);
133+
}
134+
135+
/**
136+
* Creates a ARImageTarget object to be given to {@link ViroViewARCore} to start looking
137+
* for and tracking the specified image, with a custom ID.
138+
*
139+
* @param image The {@link Bitmap} containing the image to track.
140+
* @param orientation The {@link Orientation} of the given Bitmap, which indicates where the
141+
* top of the image is. For example, if the input image is an upside-down
142+
* dollar bill, you would set the orientation to {@link Orientation#Down}
143+
* to identify right-side-up dollar bills in the world. Set to {@link
144+
* Orientation#Up} to indicate you want to identify the image as-is without
145+
* any rotation.
146+
* @param physicalWidth The real-world width of the image in meters. Note this is the width
147+
* <i>post</i>-orientation.
148+
* @param id The custom ID for this target. If null, a hashCode-based ID will be used.
149+
* This ID is used to match detected images with their corresponding targets.
150+
*/
151+
public ARImageTarget(Bitmap image, Orientation orientation, float physicalWidth, String id) {
152+
mId = (id != null) ? id : String.valueOf(this.hashCode());
133153
mOrientation = orientation;
134154
mPhysicalWidth = physicalWidth;
135155
mNativeRef = nativeCreateARImageTarget(image, mOrientation.getStringValue(), mPhysicalWidth, mId);

0 commit comments

Comments
Β (0)