Using CameraDevice and CameraSettings javacv - java

I don't know how this classes work. I am trying to know what cameras are available. Also, if possible, I would like to change settings of the camera (this I think I can figure it out by myself, but an example would be great).
Thanks.

Get the camera list you can simply use
int n = com.googlecode.javacv.cpp.videoInputLib.videoInput.listDevices();
for (int i = 0; i < n; i++) {
String info = com.googlecode.javacv.cpp.videoInputLib.videoInput.getDeviceName(i);
System.out.println(info);
}
you can get the image resolution by calling
grabber.getImageWidth();
grabber.getImageHeight();
also for set can use setImageWidth(), setImageHeight()

Related

How to get how much space a Method or a return value used?

Is it possible to know/get how much space/memory are used when a method is executed or when there is a return value? I don't want to know how much space used by the app, just some code like method or the return value. I tried the runtime.getRuntime, but from my understanding, It looks like it tells me how much space is used by the entire code/app, am I right?
EDIT :
public int [] randtotal(int times2)
{
int in1[] = new int[times2];
for (int i = 0; i<Num2; i++)
Random rand = new Random();
{
in1[times2]= rand.NextInt(5);
}
totalNum(in1);
return int1;
}
As you can see here, at the end of the code there is the "return int1;" , so I want to know when these code is executed how much space is allocated for the value here?
You can use Visualvm tool to profile the overall application and you can also profile certain package, class or function
see this link :
https://visualvm.java.net/profiler.html

Changing Filenames(Strings) through loops - Java

I want to change images at a specific location, for the purpose of animation. Can I create a loop with for change in file names. File names are like Sprite1.png, Sprite2.png ...... Sprite10.png.
for(i = 1; i <= 10; i++)
{
Display("Sprite(i).png")
}
Is something like this possible? How?
Lets say there are n files. you can achieve desired output by using the following piece of code
for(i=1;i<=n;i++){
Display("Sprite"+i+".png")
}

Equivalent of JavaScript's splice in Java

I'm trying to port some Javascript code into Java and I've reached a section where I can't seem to port the code without all sorts of errors. There are no actual exceptions thrown it just doesn't work as it should. Basically this code is part of a networking snippet that attempts to reconcile with the server when it receives a new packet because it uses client-side prediction to keep moving the player even when there's no packets to be applied.
I understand the concept but I just can't seem to put it into code. The section of code uses the splice function on an array to remove elements so I thought it'd be easy to port. I'll post the code segment of JS below along with the code segment in Java that gives me problems and tell me what I'm doing wrong. I'm pretty sure I also ported the loop wrong.
JavaScript:
var j = 0;
while (j < this.pending_inputs.length) {
var input = this.pending_inputs[j];
if (input.input_sequence_number <= state.last_processed_input) {
// Already processed. Its effect is already taken into account
// into the world update we just got, so we can drop it.
this.pending_inputs.splice(j, 1);
} else {
// Not processed by the server yet. Re-apply it.
this.entity.applyInput(input);
j++;
}
}
Java:
for (int i = 0; i < pendingInputs.size(); i++) {
if (i <= lastProcCmd) {
// Already proceesed command, remove it from pendingInputs
for (int j = 1; j < pendingInputs.size(); j++) {
pendingInputs.remove(j);
}
} else {
applyCmd(pendingInputs.get(i));
}
}
EDIT
So I changed the code to this:
// Server reconciliation
int j =0;
while (j < pendingInputs.size()) {
String cmd = pendingInputs.get(j);
if (pendingInputs.indexOf(cmd) <= lastProcCmd) {
pendingInputs.remove(j);
} else {
applyCmd(cmd);
j++;
}
}
And I still have a problem so I'm thinking it's elsewhere in the code. This is multiplayer code using client-side prediction and server reconciliation if that helps using these articles: Articles
Pending inputs is an ArrayList of Strings that represent commands such as, "Left" or, "Right." The other problem is that my network listener is on another thread even though I use sychronization blocks to prevent any ConcurrentModificationExceptions from happening in important places. His code was hard to port as JS to Java is something I'm not familiar with.
Untested, but looks close:
for (Iterator<String> iter = pendingInputs.iterator(); iter.hasNext(); ) {
String cmd = iter.next();
if(pendingInputs.indexOf(cmd) <= lastProcCmd){
iter.remove();
}else{
applyCmd(cmd);
}
}
Some things to note:
Might be wise to create classes for your commands and use polymorphism to run them
Figuring out if a command has been processed via its position in a list is error prone. If commands were pojos you could set a "has been processed" flag them remove based on that.

java - Image fits and works with jar, but not when using a String[] array to store the image names

Edit:
It was helpful to load the images only once in the default constructor, everything works much faster now. The problem, however, has changed. I can't open the jar file anymore, and if I launch it from the console using java -jar BounceTheSphinx.jar I get this
Exception in thread ''main'' java.lang.IllegalArgumentException: input == null!:
at javax.imageio.ImageIO.read<Unknown Source>
at BounceBack.PanneauJeu.<init>(PanneauJeu.java:55)
at BounceBack.FenetreJeu.<init>(FenetreJeu.java:21)
at BounceBack.MainBounceBack.main(MainBounceBack.java:11)
Line 55 from PanneauJeu.java is fondArray[j] = ImageIO.read(this.getClass().getResource(imageArray[j])); I looked on other posts, but I can't solve my problem with the solutions proposed. The thing is, I really use the same technique to load and display those images, those images exist, everything works in eclipse, yet the fondArray one always causes the problem, not the fondPerdu
I edited the code for you to see
So I wrote in the comments ''WORKS'' and ''DOESN'T WORK'' so you can see where my problem is.
public class PanneauJeu extends JPanel
{
private int i = 0;//color counter
private int j = 0;//imageArray counter
private int k = 0;//imagePerdu counter
private String[] imageArray = {"/resources/Sphinx.png", "/resources/Sphinx2.png ", "/resources/Sphinx3.png", "/resources/Sphinx4.png", "/resources/Sphinx5.png", "/resources/Sphinx6.png", "/resources/Sphinx7.png", "/resources/Sphinx8.png"};//score
private String[] imagePerdu = {"/resources/Lose5.png", "/resources/Lose6.png", "/resources/Lose7.png", "/resources/Lose8.png", "/resources/Lose9.png", "/resources/Lose10.png", "/resources/Lose11.png", "/resources/Lose12.png", "/resources/Lose13.png"};//, "Lose10.png", "Loose11.png", "Loose12.png"};
private Image fond;
private Image fondArray[] = new Image[imageArray.length];
private Image fondPerdu[] = new Image[imagePerdu.length];
public PanneauJeu()//default constructor
{
for(int j = 0; j < imageArray.length; j++)
{
//DOESN'T WORK
try
{
fondArray[j] = ImageIO.read(this.getClass().getResource(imageArray[j]));
}catch(IOException e){e.printStackTrace();}
}
for(int k = 0; k < imagePerdu.length; k++)
{
//WORKS
try
{
fondPerdu[k] = ImageIO.read(this.getClass().getResource(imagePerdu[k]));
}catch(IOException e){e.printStackTrace();}
}
}
Can anyone tell me what could possibly be wrong? Remember, everything works just fine in Eclipse.
Thank you everyone for your help
It's not entirely clear what the issue is, but there's one likely candidate:
You're loading an image every time that you want to display it.
In the case of an animation, that means trying to constantly reload lots of images. This is a burden both in terms of I/O and CPU time. What you want to do is load your images once, and then keep them around (instead of just the file names) to display when you need them. This way, your program doesn't have to be constantly loading and reloading the same data from the filesystem.
There's a reasonable chance that you have another issue, but doing this should make it easier to find.
Once you've moved your loading to happen once, if the problem persists, try launching your JAR from the command line: run java -jar <PATH TO JARFILE>, and see if it prints out any errors. There's a good chance that there's an error happening then that you can't see if you try to launch the JAR from a GUI.

Bifurcation and ridge ending point

Is there any way to find Bifurcation point and ridge ending point in a Image (hand, vein), by using a Java code only not Matlab etc.? Can I achieve this by ImageJ Library of Java?
A scientific description you find in Minutiae Extraction from Fingerprint Images.
Some algorithms are implemented in OpenCV see the segmentation section.
The OpenCV library can be linked to java using JNI.
There is an ImageJ plugin that could help you to do that:
AnalyzeSkeleton
(for the source see here )
You can extract branching points and endpoints with the help of its SkeletonResult class.
Many thanks to help me out I went through AnalyzeSkeleton and got the result in SekeletonResult Response by Using IJ. for this I have used IJ.run(imp, "Skeletonize", "");
// Initialize AnalyzeSkeleton_
AnalyzeSkeleton_ skel = new AnalyzeSkeleton_();
skel.calculateShortestPath = true;
skel.setup("", imp);
// Perform analysis in silent mode
// (work on a copy of the ImagePlus if you don't want it displayed)
// run(int pruneIndex, boolean pruneEnds, boolean shortPath, ImagePlus origIP, boolean silent, boolean verbose)
SkeletonResult skelResult = skel.run(AnalyzeSkeleton_.NONE, false, true, null, true, false);
// Read the results
Object shortestPaths[] = skelResult.getShortestPathList().toArray();
double branchLengths[] = skelResult.getAverageBranchLength();
int branchNumbers[] = skelResult.getBranches();
long totalLength = 0;
for (int i = 0; i < branchNumbers.length; i++) {
totalLength += branchNumbers[i] * branchLengths[i];
}
double cumulativeLengthOfShortestPaths = 0;
for (int i = 0; i < shortestPaths.length; i++) {
cumulativeLengthOfShortestPaths +=(Double)shortestPaths[i];
}
System.out.println("totalLength "+totalLength);
System.out.println("cumulativeLengthOfShortestPaths "+cumulativeLengthOfShortestPaths);
System.out.println("getNumOfTrees "+skelResult.getNumOfTrees());
System.out.println("getAverageBranchLength "+skelResult.getAverageBranchLength().length);
System.out.println("getBranches "+skelResult.getBranches().length);
System.out.println("getEndPoints "+skelResult.getEndPoints().length);
System.out.println("getGraph "+skelResult.getGraph().length);
System.out.println("getJunctions "+skelResult.getJunctions().length);
System.out.println("getJunctionVoxels "+skelResult.getJunctionVoxels().length);
System.out.println("getListOfEndPoints "+skelResult.getListOfEndPoints().size());
System.out.println("getListOfJunctionVoxels "+skelResult.getListOfJunctionVoxels().size());
System.out.println("getMaximumBranchLength "+skelResult.getMaximumBranchLength().length);
System.out.println("getNumberOfVoxels "+skelResult.getNumberOfVoxels().length);
System.out.println("getQuadruples "+skelResult.getQuadruples().length); this method .but I am not able to find which method in Skeleton Result class returns bifuraction point could you please help me little more thanks Amar

Categories