My device has only two focus modes, AUTO and FIXED (as per getSupportedFocusModes()).
I want to set my camera at a fixed focus distance of 'x' (x being whatever I like, or whatever I can get from the camera..). (I'm aware of setFocusMode(Camera.Parameters.FOCUS_MODE_FIXED), but this seems to be fixed only on the farthest possible setting..)
Can this be done? (Android version 4.2.2)
Not trying to completely answer the question here, just trying to give it some direction.
So, what you need here is a driver support for that kind of operation. Then at some point you'd ask the driver from your application to set a requested focus distance.
Another question is: "if anyone really needs that kind of functionality?".
Android documentation says:
public static final String FOCUS_MODE_FIXED
Focus is fixed. The camera is always in this mode if the focus is not adjustable. If the camera has auto-focus, this mode can fix the focus, which is usually at hyperfocal distance. Applications should not call autoFocus(AutoFocusCallback) in this mode.
Lets see what hyperfocal distance is.
Hyperfocal distance
From Wikipedia, the free encyclopedia
In optics and photography, hyperfocal distance is a distance beyond which all objects can be brought into an "acceptable" focus. There are two commonly used definitions of hyperfocal distance, leading to values that differ only slightly:
Definition 1: The hyperfocal distance is the closest distance at which a lens can be focused while keeping objects at infinity acceptably sharp. When the lens is focused at this distance, all objects at distances from half of the hyperfocal distance out to infinity will be acceptably sharp.
Definition 2: The hyperfocal distance is the distance beyond which all objects are acceptably sharp, for a lens focused at infinity.
The distinction between the two meanings is rarely made, since they have almost identical values. The value computed according to the first definition exceeds that from the second by just one focal length.
As the hyperfocal distance is the focus distance giving the maximum depth of field, it is the most desirable distance to set the focus of a fixed-focus camera.
So the focus is not set on the farthest possible setting, but is set to have all visible objects to be acceptably sharp.
Returning to the question.
If you happen to be a developer of this particular camera's firmware, you can add any needed IOCTLs to you driver. But then you still going to need to call them somehow. This can't be achieved without adding additional functions into the Android OS, and further recompiling of Android itself and it's underlying Linux kernel.
So it seems like you can't achieve this goal, not from the user space at least.
One potential approach to achieve that fixed focus distance is to call autoFocus at the start of the camera life-cycle. Keep calling autoFocus sporatically until a condition is met. Once the condition is met, then instead of calling autoFocus, set a flag and call takePicture instead.
This is one solution that I have come to in order to get the desired effect that you might be looking to achieve.
So within my thread that is taking pictures continuously, the code looks something like this:
if(needsFocus)
{
myCamera.autoFocus(autoFocusCallback);
}
else //Focus is not needed anymore at this point
{
if(myCamera != null)
{
myCamera.startPreview();
myCamera.takePicture(pictureCallback);
}
}
Once the condition is met, needsFocus is set to true. At this point, the focus is fixed at the place that I want it to be at. Then it won't change throughout the rest of the activities task. The condition for my case was the appearance of a particular object detected with the OpenCV library.
I might be wrong, but the way you phrase your question seems like coming from a classic DSLR lens perspective.
On an android mobile camera, you don't actually have to worry that much of a lens focal distance, unless your mobile camera allows that (which does not seem to be the case, as you mention it just allows auto or fixed, instead of infinite, macro, continuous-video, etc).
You can just set local areas on the camera to focus and let the sdk do its work. If the object touched on the camera image is far or near it's the sdk work to calculate accordingly and focus for you.
For an example, try this open-source camera project.
Related
I am thinking to put markers on images taken from camera output similar to what Google Photoscan application does. As I can see the Google Photoscan app puts four solid circle on image which is overlay and then moves the center hallow circle towards all four solid circles and capture the four images. Stitch them together to create a high quality image.
Screenshots for reference (The Solid dots you can see are always there even on the same color background Even if you move the camera around and back to initial position they will display at same position):
The Solid dots you can see are always there even on the same color background Even if you move the camera around and back to initial position they will display at same position
I am very curious how they are able to stable those four solid circles? Are they using any optical flow algorithm ? Or any motion sensors ? I tested application on white colour or same colour background those dots stay stable.
I implemented this functionality using optical flow algorithm (Lucas–Kanade method in openCV).But they are not stable when I am using them on same colour background or on white colour background (basically in Lucas–Kanade algorithm if it does not find the feature it tries to shift that point). Here is the screenshot for my implementation:
You are almost close. Using single sensor either alone gyroscope or compass will not work. By combining result of these, we can achieve your requirement.
Ingredient 1 : Accelerometer
Accelerometers in mobile phones are used to detect the orientation of the phone. The gyroscope, or gyro for short, adds an additional dimension to the information supplied by the accelerometer by tracking rotation or twist. An accelerometer measures linear acceleration of movement.
Ingredient 2 : gyroscope
In practice, an accelerometer will measure the directional movement of a device but will not be able to resolve its lateral orientation or tilt during that movement accurately unless a gyro is there to fill in that info.
Ingredient 3 : Digital compass
The digital compass that's usually based on a sensor called magnetometer provides mobile phones with a simple orientation in relation to the Earth's magnetic field. As a result, your phone always knows which way is North so it can auto rotate your digital maps depending on your physical orientation.
With an accelerometer you can either get a really "noisy" info output
that is responsive, or you can get a "clean" output that's sluggish.
But when you combine the 3-axis accelerometer with a 3-axis gyro, you
get an output that is both clean and responsive in the same time.
Coming back to your question, Lucas–Kanade method in openCV result delayed causing glitch or the sensors not giving accurate result from your device.
It's more of a CV problem.
I really appreciate #Jeek Axio's answer. You can use multiple sensors on Android device as 'prime' factors in CV problem.
However as of state-of-the-art CV methods, it's possible to solve this tracking problem on a very good accuracy.
You may use EKLT, PointTrack methods to track the feature points.
There's also a full-featured toolbox called FTK.
I try to use Dynamic Time Warping (DTW) to detect gestures performed with a smartphone by using the accelerometer sensor. I already implemented a simple DTW-algorithm.
So basicly I am comparing arrays of accelerometer-data (x,y,z) with DTW. The one array contains my predefiend gesture, the other should contain the measured values. My problem is, that the accelerometer-sensor measures continously new values and I don't know when to start the comparison with my predefined value-sequence.
I would need to know when the gesture starts and when it ends, but this might be different with different gestures. In my case all supported gestures start and end at the same point, but as far as I know I can't calculate the traveled distance from acceleration reliably.
So to sum things up: How would you determine the right time to compare my arrays using DTW?
Thanks in advance!
The answer is, you compare your predefined gesture to EVERY
subsequence.
You can do this in much faster than real time (see [a]).
You need to z-normalize EVERY subsequence, and z-normalize your predefined gesture.
So, by analogy, if you stream was.....
NOW IS THE WINTER OF OUR DISCONTENT, MADE GLORIOUS SUMMER..
And your predefined word was made, you can compare with every marked word beginning (denoted by white space)
DTW(MADE,NOW)
DTW(MADE,IS)
DTW(MADE,THE)
DTW(MADE,WINTER)
etc
In your case, you don’t have makers, you have this...
NOWISTHEWINTEROFOURDISCONTENTMADEGLORIOUSSUMMER..
So you just test every offset
DTW(MADE,NOWI)
DTW(MADE, OWIS)
DTW(MADE, WIST)
DTW(MADE, ISTH)
::
DTW(MADE, TMAD)
DTW(MADE, MADE) // Success!
eamonn
[a] https://www.youtube.com/watch?v=d_qLzMMuVQg
You want to apply DTW not only to a time-series, but to a continously evolving stream. Therefore you will have to use a sliding window of n recent data points.
This is exactly, what eamonn described in his second example. His target pattern consists of 4 events (M,A,D,E) and therefore he uses a sliding window with length of 4.
Yet in this case, he makes the assumption, that the data stream contains no distortions, such as (M,A,A,D,E). The advantage of DTW is that it allows these kind of distortions and yet recognizes the distorted target pattern as a match. In your case, distortions in time are likely to happen. I assume that you want equal gestures performed either slow or fast as the same gesture.
Thus, the length of the sliding window must be higher than the length of the target pattern (to be able to detect a slow target gesture). This is computationally expensive.
Finally, my point is: I want to recommed you this paper
Spring algorithm by Sakurai, Faloutsos and Yamamuro.
They optimized the DTW algorithm for datastreams. You will no longer need more than n*n computations per incoming event but only n. It basically is DTW but cutting down all unneccesary computations and only taking the best possible alignment of the template onto the stream into account.
p.s. most of what I know about time-series and pattern matching, I learned by reading what Eamonn Keogh provided. Thanks a lot, Mr. Keogh.
I am working on a project in which i have to calculate my device height from ground. I have searched all over the internet but could not find any solution.
Please, Anyone tell me what to do..??
Take it with a grain of salt, a bit of humor and a sense of philosophy. Change the barometer by your smartphone.
http://naturelovesmath-en.blogspot.ca/2011/06/niels-bohr-barometer-question-myth.html
First it has to be clarified, if "height from ground" means altitude in meaning "height from sea level" or you mean, how far the phone is away from the floor, when you have it in your hands.
For the second case:
Like SonicWind states, you could do the trick using the camera.
It would require calibration of the camera and to have a standard object.
Take a picture of the standard object which has to be positioned on the ground with standard zoom.
Recognize the object size - or select it in the picture, and calculate the distance to the object.
-> you have the distance to the ground.
The object might be also your shoes etc. So if the application should be for multiple users, you might allow them to enter their shoe sizes ;)
This is an odd one..but OK..I like a challenge. The only way to realistically do this is to run a sonar sensor on the phone(easily done on arduino). Other than that..all you can do is set up the code to read the accelerators to guesstimate the distance(put the phone on the ground and pick it up to the height you want. It appears to be impossible to do otherwise(maybe some concept use of the camera..)
I see queries related to opencv motion detection, but my requirement is much simpler , so i am asking the question again .
I would like to analyse video frames and see if something has changed in the frame. Any kind of motion occurring in the frame has be recognized. I just want to get notified if something happens. I don't need to track/ draw contours.
Attempts made :
1) Template matching using OpenCV ( TM_CCORR_NORMED ).
I get the similarity index using cvMinMaxLoc &
if( sim_index > threshold )
"Nothing chnged"
else
"Changed
Problem faced :
I couldn't find a way to decide on how to set thresholds. The values of false match and perfect were very close.
2) Method 2
a) Make running average
b) Take abs difference between current frame and moving average.
c) Threshold it and made it binary
d) Count the number of non zero values
Again am stuck with how to threshold it, because i am getting a large number of non zero values even for very similar frames.
Please advice me on what approach i should take. Am i going in the right direction with the above two methods, or is there a simple method which can work in all most generic scenarios.
Method 2 is generally regarded as the most simple method for motion detection, and is very effective if you have no water, swaying trees or highly variable lighting conditions in your video.
Normally you implement it like this:
motion_frame=abs(newframe-running_avg);
running_avg=(1-alpha)*running_avg+alpha*newframe;
You can threshold the motion_frame if you want, then count the nonzeroes. But you could also just sum the elements of the motion_frame and threshold that instead (be sure to work with floating point numbers). Optimizing the parameters for this is pretty easy, just make two trackbars and play around with it. Typically alpha is around [0.1; 0.3].
Lastly, it is probably overkill to do this on entire frames, you could just use subsampled versions and the result will be very similar.
Is it possible to measure distance to object with phone camera?
I mean, in my application I start the camera, facing the camera to the object (lets say house) and then press the button and it calculates the distance and shows me in screen.
If it's possible where I can find some tutorial or information about it?
I accept the question has been answered adequately (with the obvious caveats of requiring level ground and possible accuracy problems) but for those who don't believe it can be done or that it needs a video camera, let me explain the low-level math needed to do it....
The picture above shows me standing outside my house. The horizontal (d) is the distance I want to measure and the vertical (h) is the height above the ground at which I'm holding the camera. In this case 'h' is a known value when I'm holding the android camera at eye-level (approx 67 inches or 1.7 metres). When I tilt the camera to aim it directly at the point my house meets the ground, all the software needs to do is work out the angle (a) relative to vertical and it can calculate 'd' using...
d = h * tan a
Well you should read how ithinkdiff.com "measures" the distance:
Uses the angle of the iPhone to estimate the distance to a point on the ground.
Hold the iPhone in front of you, align the point in the camera and get a direct
reading of the distance. The distance can then be used in the speed tool.
So basically it takes the height of where you hold the phone (eye-level), then you must point the camera to the point where object touches the ground. Then the phone measures the inclination and with simple trigonometry it calculates distance.
This is of course not very accurate. It gets less accurate the further the object is. Also it assumes that the ground is level.
Nope. The camera can only give you image data and an image alone doesn't give you enough information to give you depth information. If you had multiple images that you had location information for or even video you could then process it to triangulate the distance, but a single image alone would not be enough to give you a distance.
You can use the technique used by our eye to get perspective of depth and distance.
1) Get 2 images of the same object from two different camera positions.
2) The distance or pixels between object in 2 images is inversely proportional to distance between camera and object.
The implementation is available at https://github.com/agnelvishal/Distance-between-camera-and-object
Here is the research paper http://dsc.ijs.si/files/papers/S101%20Mrovlje.pdf
You have the angle in the phone's accelerometer. If you calculate the tangent of this angle and multiply it by the height of the camera lens, you get the distance.
I think this App uses the approach MisterSquonk mentioned (its free). Watch the "Trigonometry" technique.
I think by using FastCV you can calculate the distance between Camera and the object. In this You dont need to know the angle or the Position of camera that you are holding above ground Level. take a look at this question here
One way to achieve this is using the DPI's in your device. You can take a picture and calculate the height. But you'll need another object as a reference and then you will be able to know the problem with this method could be the perspective between the objects
I think it could be possible doing that using the phone camera. I know that the modern phones use lenses to focus on a object. If it is possible to know their focal length and their position(displacement) to focus on the chosen object it's also possible to determinate the distance.
No. Only with two cameras in stereo mode, like the xbox 360 kinect. It takes at least 3 points to triangulate distance.