I'm trying out detecting multiple augmented images with AR core, with
https://developers.google.com/ar/develop/java/augmented-images/guide
and other online tutorials. Currently, I have the database setup and loaded with images. However
Collection<AugmentedImage> augmentedImages = frame.getUpdatedTrackables(AugmentedImage.class);
did not seem to capture and match the feature points of my images in my db.
Can you advise me about what I need to do?
I have set up and loaded multiple images from db. The app is able to detect only 1 image previously. However, after tweaking my code to detect multiple images, it did not work properly.
Tried researching and debugging however, still unable to solve it.
private void onUpdateFrame(FrameTime frameTime)
{
Frame frame = arFragment.getArSceneView().getArFrame();
Collection<AugmentedImage> augmentedImages = frame.getUpdatedTrackables(AugmentedImage.class);
for (AugmentedImage augmentedImage : augmentedImages)
{
int i =augmentedImages.size();
Log.d("NoImage",""+i);
if (augmentedImage.getTrackingState() == TrackingState.TRACKING)
{
if (augmentedImage.getName().contains("img1") && !modelAdded)
{
renderObject(arFragment, augmentedImage.createAnchor(augmentedImage.getCenterPose()),R.raw.car);
modelAdded = true;
}
else if (augmentedImage.getName().contains("img2") && !modelAdded)
{
renderObject(arFragment, augmentedImage.createAnchor(augmentedImage.getCenterPose()), R.raw.car);
modelAdded = true;
}
else if (augmentedImage.getName().contains("img3") && !modelAdded)
{
renderObject(arFragment, augmentedImage.createAnchor(augmentedImage.getCenterPose()), R.raw.car);
modelAdded = true;
}
}
}
}
Related
I am taking a series of pictures using Android Camera2 API for real time pose estimation and environment reconstruction (the SLAM problem). Currently I simply save all of these pictures in my SD card for off-line processing.
I setup the processing pipeline according to google's Camera2Basic using a TextureView as well as an ImageReader, where they are both set as target surfaces for a repeat preview request.
mButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(mIsShooting){
try {
mCaptureSession.stopRepeating();
mPreviewRequestBuilder.removeTarget(mImageReader.getSurface());
mCaptureSession.setRepeatingRequest(mPreviewRequestBuilder.build(), mCaptureCallback, mBackgroundHandler);
mIsShooting = false;
} catch (CameraAccessException e) {
e.printStackTrace();
}
}
else{
try {
mCaptureSession.stopRepeating();
mPreviewRequestBuilder.addTarget(mImageReader.getSurface());
mCaptureSession.setRepeatingRequest(mPreviewRequestBuilder.build(), mCaptureCallback, mBackgroundHandler);
mIsShooting = true;
} catch (CameraAccessException e) {
e.printStackTrace();
}
}
}
});
The ImageReader is added/removed when pressing the button. The ImageReader's OnImageAvailableListener is implemented as follow:
private ImageReader.OnImageAvailableListener mOnImageAvailableListener = new ImageReader.OnImageAvailableListener() {
#Override
public void onImageAvailable(ImageReader reader) {
Image img = reader.acquireLatestImage();
if(null == img){
return;
}
if(img.getTimestamp() <= mLatestFrameTime){
Log.i(Tag, "disorder detected!");
return;
}
mLatestFrameTime = img.getTimestamp();
ImageSaver saver = new ImageSaver(img, img.getTimestamp());
saver.run();
}
};
I use acquireLatestImage (with buffer size set to 2) to discard old frames and have also checked the image's timestamp to make sure they are monotonously increasing.
The reader does receive images at an acceptable rate (about 25fps). However a closer look at the saved image sequence show they are not
always saved in chronological order.
The following pictures come from a long sequence shot by the program (sorry for not being able to post pictures directly :( ):
Image 1:
Image 2:
Image 3:
Such disorder does not occur very often but they can occur any time and seems not to be an initialization problem. I suppose it has something to do with the ImageReader's buffer size as with larger buffer less "flash backs" are occurred. Does anyone have the same problem?
I finally find that such disorder disappears when setting ImageReader's format to be YUV_420_888 in its constructor. Originally I set this field as JPEG.
Using JPEG format incurs not only large processing delay but also disorder. I guess the conversion from image sensor data to desired format utilizes other hardware such as DSP or GPU which does not guarantee chronological order.
Are you using TEMPLATE_STILL_CAPTURE for the capture requests when you enable the ImageReader, or just TEMPLATE_PREVIEW? What devices are you seeing issues with?
If you're using STILL_CAPTURE, make sure you check if the device supports the ENABLE_ZSL flag, and set it to false. When it is set to true (generally the default on devices that support it, for the STILL_CAPTURE template), images may be returned out of order since there's a zero-shutter-lag queue in place within the camera device.
I got this headache problem and I can't seem to fix the issue. What I am doing I have a machine that a computer is hooked up too and when ever a condition is true it will take a picture. But the issue is when it does take a picture it sometimes weird, View below. I'v tried inverting the picture but not everything is backward. I looked everywhere... nothing helped me out. I tried many different sample codes they either don't work or still have this issue.
Normal picture:
http://imgur.com/ve4bp9M
Weird Picture:
http://imgur.com/5Z46oPz
public Mat getCapture(){
if(camera==null || !camera.isOpened()){
camera = new VideoCapture(0);
setCameraValues();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
Mat m = null;
if(!camera.isOpened()){
System.out.println("Error");
}
else {
m = new Mat();
while(true){
camera.read(m);
if (!m.empty()){
//Mat file is not empty
break;
}
}
}
camera.release();
return m;
}
Below is sets the camera's settings the focus, zoom, brightness ect.
public void setCameraValues()
{
this.camera.set(28, ((Integer)this.values.get(0)).intValue());
this.camera.set(27, ((Integer)this.values.get(1)).intValue());
this.camera.set(10, ((Integer)this.values.get(2)).intValue());
this.camera.set(11, ((Integer)this.values.get(3)).intValue());
this.camera.set(12, ((Integer)this.values.get(4)).intValue());
this.camera.set(15, ((Integer)this.values.get(5)).intValue());
this.camera.set(20, ((Integer)this.values.get(6)).intValue());
this.camera.set(33, ((Integer)this.values.get(7)).intValue());
this.camera.set(34, ((Integer)this.values.get(8)).intValue());
this.camera.set(3, ((Integer)this.values.get(9)).intValue());
this.camera.set(4, ((Integer)this.values.get(10)).intValue());
}
EDIT:
The webcam I am using is Microsoft LifeCam HD
I have a long standing problem with images (used for map pins) I am using and it keeps getting worse as resolutions get higher. If I use one image, it is fine to just have it in drawable directories and specify that image. Works find with different sizes and resolutions. However, I am pulling the image name from a database on the fly. So it is working fine to have the images in the assets directory but then it is one and only one image for all resolutions. Not good nowadays as they are too small on higher end phones now.
So my goal is to grab the image name from the database and then be able to use the drawable directories and have different sizes. It seems like this would be possible but everything I try fails.
This works specifying one image from the resources directories:
public void run(){
if (!(llat == 0) && !(llon == 0)) {
if (ests == null || ests.size() == 0
|| poisPinpoints.size() == 0) {
ests = DBManager.getEstablishments();
for (Establishment est : ests) {
try {
est_pin_bmp = BitmapFactory.decodeResource(getResources(),R.drawable.mil_pushpin);
poisPinpoints.put(
est.getPoiType().getPushpin(), est_pin_bmp);
} catch (Exception e) {
e.printStackTrace();
}
}
}
This code is used when I have multiple images pulled from the database...but it is only one size from the assets directory:
public void run(){
if (!(llat == 0) && !(llon == 0)) {
if (ests == null || ests.size() == 0
|| poisPinpoints.size() == 0) {
ests = DBManager.getEstablishments();
for (Establishment est : ests) {
try {
Bitmap bm = BitmapFactory
.decodeStream(PlayPlaces.this
.getAssets().open(
est.getPoiType()
.getPushpin()));
poisPinpoints.put(
est.getPoiType().getPushpin(), bm);
} catch (Exception e) {
e.printStackTrace();
}
}
}
you probably want to take a look into this method Resources.getIdentifier()
with it you can specify something like:
String resName = est.getPoiType().getPushpin();
int drawId = getResources().getIdentifier(resName , "drawable", getPackageName());
est_pin_bmp = BitmapFactory.decodeResource(getResources(), drawId);
I'm using Universal Image Loader to display images in my app in listviews. I'm using UnlimitedDiscCache since this is the fastest cache mechanism according to the documentation.
However, I would like to clear the disc cache when my app is closed (e.g. in onStop()) but only the oldest cached files that exceed a given limit should be deleted (like TotalSizeLimitedDiscCache does).
I am aware of ImageLoader.clearDiscCache() but in my case this clears the complete cache since I am using UnlimitedDiscCache before...
So I would like to have the fastest cache mechanism when the user is loading and scrolling the listviews and do the slow cache clear when the user is no longer interacting with the app.
Any ideas how I can achieve this?
check this from here https://stackoverflow.com/a/7763725/1023248 may help you..
#Override
protected void onDestroy() {
// closing Entire Application
android.os.Process.killProcess(android.os.Process.myPid());
Editor editor = getSharedPreferences("clear_cache", Context.MODE_PRIVATE).edit();
editor.clear();
editor.commit();
trimCache(this);
super.onDestroy();
}
public static void trimCache(Context context) {
try {
File dir = context.getCacheDir();
if (dir != null && dir.isDirectory()) {
deleteDir(dir);
}
} catch (Exception e) {
// TODO: handle exception
}
}
public static boolean deleteDir(File dir) {
if (dir != null && dir.isDirectory()) {
String[] children = dir.list();
for (int i = 0; i < children.length; i++) {
boolean success = deleteDir(new File(dir, children[i]));
if (!success) {
return false;
}
}
}
// <uses-permission
// android:name="android.permission.CLEAR_APP_CACHE"></uses-permission>
// The directory is now empty so delete it
return dir.delete();
}
If you want to clear the cache from the memory, you can use the following code:
MemoryCacheUtils.removeFromCache(imageUri, ImageLoader.getInstance().getMemoryCache());
If you also want to clear the cache in the disk, you can use the following code:
DiscCacheUtils.removeFromCache(imageUri, ImageLoader.getInstance().getDiscCache());
This is a much simpler way of clearing the cache.
You can find similar answers in this thread:
How to force a cache clearing using Universal Image Loader Android?
I hope this information was helpful. :)
I'm trying to load installed packages' icons into a listview, but they are not showing in anyway, searched and used everything I found on the web but they just won't show, while they work if I use
R.drawable.ic_launcher
So I guess it's not a layout-related issue.
Here's the code I'm using
for(int i = 0; i < numeroElementi; i++){
boolean nonSystem = (packages.get(i).flags & ApplicationInfo.FLAG_SYSTEM) == 0;
if(nonSystem == true){
HashMap<String,Object> app = new HashMap<String,Object>();
app.put("appName", packages.get(i).loadLabel(pm)); // these both work
app.put("appPackageName", packages.get(i).packageName);
try {
//app.put("appIcon", pm.getApplicationIcon(packages.get(i).packageName));
//app.put("appIcon", packages.get(i).icon + "");
//app.put("appIcon", packages.get(i).loadIcon(pm));
app.put("appIcon",packages.get(i).icon);
//app.put("appIcon", R.drawable.ic_launcher); <- this works
} catch (NameNotFoundException e) {
app.put("appIcon", R.drawable.ic_launcher);
}
installedList.add(app);
}
}
Is then there another way to grab the icon? As said earlier, if I force the ic_launcher icon, then it works... testing with packages.get(i).icon I found out that some of the voices have got the ic_launcher icon shown, so I thought that method just directed to that specific icon... anyone can help me get this work, please?