Images on a Image - java

I am new on this community and i have no idea what I have to search for. So I hope there is no thread like this.
I want to create a java Android App in Android Studio where I can open a floor plan(image) and insert icons(images). If i click once on the icon it should be movable and the size of the icons should be adjustable with a seekbar.
I googled for these functions and the only thing I found was that:
https://developer.android.com/guide/topics/graphics/2d-graphics.html
Can someone tell me which is the best way to do that?

You can use normal ImageViews https://developer.android.com/reference/android/widget/ImageView.html
with events (OnClick, OnTouch).
If you want to resize view, check this answer
-https://stackoverflow.com/a/14283837/8180966
For rotation
//#param rotation The degrees of rotation.
imageView.setRotation(float rotation);
If you want your icons to look nice at any size, you should look at Vector Graphics (https://developer.android.com/studio/write/vector-asset-studio.html)
Hope, this will help :)

You may please visit the following page (especially layer list section of the page) of android developer site. There are a few things which you may be interested in and which may serve either as a solution or an alternative to your problem.
https://developer.android.com/guide/topics/resources/drawable-resource.html

Related

Real time logo detection in live camera preview with OpenCV on Android

I am new to computer vision but I am trying to code an android app which does the following:
Get the live camera preview and try to detect one logo in that (i have the logo in my resources). In real-time. Draw a rect around the logo if found. If there is no match, dont draw the rectangle.
I already tried a couple of things including template-matching and feature detection using ORB.
Why that didnt work:
Template-matching:
Issues with scaling and rotation. I tried a multi scale variant of it but a) the performance was really bad and b) the rectangle was of course always shown trying to search for the image. There was no way to actually confirm in the code if the logo was found or not.
ORB feature detection:
Also pretty slow (5-6 fps) but it worked ok-ish. The other problem was that also i never could be sure if the logo was in the picture or not. ORB found random matches even if the logo was not in the picture.
Like I said, I am very new to this. I would appreciate the help on what would be the best way to achieve:
Confirm if a picture A (around 200x200 pixels) is in ROI of camera picture (around 600x600 pixels).
This shouldnt take longer than 50ms per frame. I dont know if thats even possible though. So if a correct way to do this would take a bit longer than that, I would just do the work in a seperate thread and only analyze like every fifth camera frame or so.
Would appreciate any hints or code examples on how to achieve that. Thank you!
With logo detection, I would highly recommend using OpenCV HaarClassifier. It is easy to generate training samples from a collection of images of the logo, or one logo image with many distortions.
If you can use a few rules like the minimum and maximum size of the logo to be detected, and possible regions on the image where it can appear, you can run the detector at a speed better than you mention with ORB.

How to resize imageicon with same quality

I`m currently making an application to manage other application on windows.
when i resize the icon it change quality
i`m getting icon by this code
ShellFolder shell = ShellFolder.getShellFolder(new File(load1.getString("Path")));
image = shell.getIcon(true);
And when i resize it it change the quality.
My resize code is
sIMG = image.getScaledInstance(45, 45, Image.SCALE_AREA_AVERAGING);
What i want to do to keep the quality of the icon.
Please help.
I'm assuming you want to re-size your icon to look the same no matter what size you change it to. Regular images will are composed of pixels therefore lost of quality is inevitable.
When I did a web design project at my school I learned about Vector images(.svg).
Summary Of Vector Vs Bitmap http://etc.usf.edu/techease/win/images/what-is-the-difference-between-bitmap-and-vector-images/
Of course anyone please correct me if I'm wrong but I think vectors is the only way you can achieve your goal assuming that I'm understanding your question. Vector image quality does not change much or at all on re-size.
Java doesn't natively support Vector Images but follow this tutorial and you should achieve your goal. (It's not really a tutorial more like copy and paste)
http://plindenbaum.blogspot.com/2009/07/simple-java-based-svg-renderer.html
Also this link will let you convert your existing images to SVG
http://vectormagic.com/home
(you get 2 downloads when you sign up) There are other tools to convert to SVG but this was the quickest solution I could find. If you're good with Photoshop I think I saw some tutorials for it but don't quote me on that.
I hope this is what you were looking for best of luck to.
you can resize any image by the following code.
$thumb = new Imagick();
$thumb->readImage('myimage.gif'); $thumb->resizeImage(320,240,Imagick::FILTER_LANCZOS,1);
$thumb->writeImage('mythumb.gif');
$thumb->clear();
$thumb->destroy();
For more information please go to the following link.
resize image
resize optimized image

Image Importing & Painting in Android Java

Recently, I have taken java and now am heading into Android Java.
However, Android has quite a few different things to tackle when programming.
So as my title says, how can I Import an image from my /res folder and paint it on the screen?
Usually, I would do something like this.
import java.awt.*
And in main class
public Image img;
And in public void paint
case CASE:
g2d.drawimage(...)
break
This doesn't seem to work in android.
Can someone explain how you could import and display images in a location in android?
It's great to see someone new trying out android development.
As for your question you could use and ImageView though if you are looking for something more dynamic then you should use a canvas. It will allowing for drawing images and animations.
I highly recommend you check out these tutorials:
Here is a list of 200 android tutorials that really helped me start out. Though some go over features that are now deprecated.
Android Tutorials
Here is where the videos start going over basic game making. It goes from video #61 to about #80.
Android Tutorial #61
These videos can help you draw a basic image or make a simple game if that's what your looking for. Though I recommend you go learn as much of the basics as you can before going into anything really complicated.
Don't overextend yourself with something to difficult to begin with because it migh leave your frustrated with the entire android concept.
Hope this helps.
u can add images/picture in the res/drawables
http://developer.android.com/guide/topics/graphics/2d-graphics.html
Also different devices use different resolutions
http://developer.android.com/guide/practices/screens_support.html
use a ImageView widget to display the image
image = (ImageView) findViewById(R.id.imageView1);
image.setImageResource(R.drawable.android);
this is assuming you have a file name android.png|jpg|gif etc in your drawable folder. If you want to use a image that is selected at runtime check here. How to set the image from drawable dynamically in android?

How to draw a cross on Google Maps?

I have following task - I need to draw on Google Maps a cross with certain coordinates. I know how can I do it using ItemOverlay but I think that there is means without using a custom marker. I need simple black cross with my coordinates. Please, tell me, is it possible?
UPDATE: I don't want to use ItemOverlay because I need to make a custom drawable for it and I hope there is simple android internal elements for it.
I'm sorry, but using Overlays seems to be the only way of drawing any line on Google Maps.
You could draw an ImageView right over the google maps view (with absolute positioning using margins). But then you'd have to take care of coord conversion (and reacting to user scrolling, zooming the map) "by hand".
I think you could also use SurfaceView fully aligned to google maps view and draw your marker right on it.
But both solutions are pretty much overkill; you're better off using ItemizedOverlay unless you have a really good reason no to - in which case you might wanna add some info on what's the reason, maybe we'll find you a nice solution to that one :)

Open webcam and set as background (question)

Best reader,
I'm stuck on one of my concepts.
I'm making a program which classroom children can measure themselves with.
This is what the program includes;
- 1 webcam (only used for a simple webcam view.)
- 2 phidgets (don't mind these.)
So, this was my plan. I'll draw a rectangle on the webcamview and make it repaint itself constantly.
When the repainting is stopped by one of the phidgets, the rectangle's value will be returned in centimeters or meters.
I've already written the code of the rectangle that's repainting itself and this was my result:
(It's a roundRectangle, the lines are kind of hard to see in this image, sorry about that.)
As you can see, the background is now simply black.
I want to set the background of this JFrame as a webcam view (if possible) and then draw the
rectangle over the webcam view instead of the black background.
I've already looked into jmf, fmj and such but am getting errors even after checking my webcam path and adding the needed jar libraries. So I want to try other options.
So;
- I simply want to open my webcam, use it as background (yes live stream, if possible in some way).
And then draw this rectangle over it.
I'm thus wondering if this is possible, or if there's other options for me to achieve this.
Hope you understand my situation, and please ask if anything's unclear.
EDIT:
I got my camera to open now trough java. The running camera is of type "Process".
This is where I got the code for my camera to open: http://www.linglom.com/2007/06/06/how-to-run-command-line-or-execute-external-application-from-java/
I adjusted mine a little so it'll open my camera instead.
But now I'm wondering; is it possible to set a process as background of a JFrame?
Or can I somehow add the process to a JPanel and then add it to a JFrame?
I've tried several things without any succes.
My program as it is now, when I run it, opens the measuring frame and the camera view seperatly.
But the goal is to fuse them and make the repainting-rectangle paint over the camera view.
Help much appreciated!
I don't think it's a matter of setting a webcam stream as the background for your interface. More likely, you need to create a media player component, add it to your GUI, and then overlay your rectangles on top of that component.
As you probably know from searching for Java webcam solutions in Stack Overflow already, it's not easy, but hopefully the JMF Specs and API Guide will help you through it. The API guide is a PDF and has sections on receiving media streams, as well as sample code.

Categories