I am trying to put a collision-shape onto my model.
But everytime I init the game, I get an NegativeArraySizeException.
private void createSoundBit(float x, float y, float z)
{
Spatial npc1 = assetManager.loadModel("Models/sound/sound.j3o");
npcNode.attachChild(npc1);
CollisionShape noteshape = CollisionShapeFactory.createDynamicMeshShape(npc1);
npcRigid = new RigidBodyControl(noteshape,123.0f);
npcRigid.setFriction(0f);
npcRigid.setMass(60f);
npcRigid.setPhysicsLocation(new Vector3f(x,y,z));
collmanager = new CollManager();
getPhysicsSpace().addCollisionListener(collmanager);
npc1.addControl(npcRigid);
bulletAppState.getPhysicsSpace().add(npcRigid);
rootNode.attachChild(npcNode);
}
I don't know why it happens
Stacktrace:
java.lang.NegativeArraySizeException
at com.jme3.bullet.collision.shapes.HullCollisionShape.getPoints(HullCollisionShape.java:71)
at com.jme3.bullet.collision.shapes.HullCollisionShape.<init>(HullCollisionShape.java:24)
at com.jme3.bullet.util.CollisionShapeFactory.createSingleDynamicMeshShape(CollisionShapeFactory.java:241)
at com.jme3.bullet.util.CollisionShapeFactory.createCompoundShape(CollisionShapeFactory.java:112)
at com.jme3.bullet.util.CollisionShapeFactory.createCompoundShape(CollisionShapeFactory.java:94)
at com.jme3.bullet.util.CollisionShapeFactory.createDynamicMeshShape(CollisionShapeFactory.java:188)
at Main.createSoundBit(Main.java:206)
at Main.simpleInitApp(Main.java:83)
at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:225)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:130)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:207)
at java.lang.Thread.run(Thread.java:722)
For me it can be one of two things: your file sound.j3o is corrupted or there is a bug in jmonkeyengine. Try to load some other file and see what's happening. Part of source where is a problem:
FloatBuffer vertices = mesh.getFloatBuffer(Type.Position);
vertices.rewind();
int components = mesh.getVertexCount() * 3;
float[] pointsArray = new float[components];
// ...
So, looks like mesh.getVertexCount() returned negative value.
Related
Good morning everyone. I am currently working on a project in which I have to detect object coordinates within an image with high precision. I have tried using a normal chessboard for camera calibration but the reprojection error was too high so I decided to use the Charuco calibration pattern. I am working with OpenCv 3.4 and Java (project constraint). Since the Aruco function are not included in OpenCv for Java I created a new package in my project which includes the necessary classes. The Aruco code is the one that you can find in the following link :
Aruco Code Github
The code that I'm executing is the following:
protected void captureImagesCharuco() {
int squaresX = 5;
int squaresY = 7;
float squareLength = (float) 37.0;
float markerLength = (float) 22.0;
int calibrationFlags = 0;
float aspectRatio = 1;
DetectorParameters detectParams = DetectorParameters.create();
detectParams.set_adaptiveThreshWinSizeMin(3);
detectParams.set_adaptiveThreshWinSizeMax(23);
detectParams.set_adaptiveThreshWinSizeStep(10);
detectParams.set_adaptiveThreshConstant(7);
detectParams.set_minMarkerPerimeterRate(0.03);
detectParams.set_maxMarkerPerimeterRate(4.0);
detectParams.set_polygonalApproxAccuracyRate(0.05);
detectParams.set_minCornerDistanceRate(10);
detectParams.set_minDistanceToBorder(3);
detectParams.set_minMarkerDistanceRate(0.05);
detectParams.set_cornerRefinementWinSize(5);
detectParams.set_cornerRefinementMaxIterations(30);
detectParams.set_cornerRefinementMinAccuracy(0.1);
detectParams.set_markerBorderBits(1);
detectParams.set_perspectiveRemovePixelPerCell(8);
detectParams.set_perspectiveRemoveIgnoredMarginPerCell(0.13);
detectParams.set_maxErroneousBitsInBorderRate(0.04);
detectParams.set_minOtsuStdDev(5.0);
detectParams.set_errorCorrectionRate(0.6);
Dictionary dictionary = Aruco.getPredefinedDictionary(0);
CharucoBoard charucoBoard = CharucoBoard.create(squaresX, squaresY, squareLength, markerLength, dictionary);
List<List<Mat>> charucoCorners = new ArrayList<>();
List<Mat> charucoIds = new ArrayList<>();
List<Mat> validImgs = new ArrayList<>();
Size imgSize = new Size();
int nFrame = 0;
File[] listImages = imageDirectory.listFiles();
for(File file : listImages) {
String src = file.getAbsolutePath();
Mat imgRead = Imgcodecs.imread(src,Imgcodecs.IMREAD_COLOR);
imgSize = imgRead.size();
Mat imgCopy = new Mat();
Mat ids = new Mat();
List<Mat> rejectedCorners = new ArrayList<>();
List<Mat> corners = new ArrayList<>();
if (!imgRead.empty()){
Aruco.detectMarkers(imgRead, dictionary, corners, ids);
Aruco.refineDetectedMarkers(imgRead, (Board)charucoBoard, corners, ids, rejectedCorners);
Mat currentCharucoCorners = new Mat();
Mat currentCharucoIds = new Mat();
int idsSize = ids.rows()*ids.cols();
if(idsSize>0) {
Aruco.interpolateCornersCharuco(corners, ids, imgRead, charucoBoard, currentCharucoCorners, currentCharucoIds);
}
imgRead.copyTo(imgCopy);
if(idsSize<0) {
Aruco.drawDetectedCornersCharuco(imgCopy, currentCharucoCorners);
}
if(currentCharucoCorners.total()>0) {
Aruco.drawDetectedCornersCharuco(imgCopy, currentCharucoCorners, currentCharucoIds, new Scalar(255,0,0));
}
charucoCorners.add(corners);
charucoIds.add(currentCharucoIds);
validImgs.add(imgRead);
nFrame++;
}
}
intrinsic.put(0, 0, 1);
intrinsic.put(1, 1, 1);
List<Mat> allCharucoCorners = new ArrayList<>();
List<Mat> allCharucoIds = new ArrayList<>();
for(int i =0;i<nFrame;i++) {
Mat currentCharucoCorners = new Mat();
Mat currentCharucoIds = new Mat();
Aruco.interpolateCornersCharuco(charucoCorners.get(i), charucoIds.get(i), validImgs.get(i), charucoBoard, currentCharucoCorners, currentCharucoIds,intrinsic,distCoeffs,4);
allCharucoCorners.add(currentCharucoCorners);
allCharucoIds.add(currentCharucoIds);
}
double repError = Aruco.calibrateCameraCharuco(allCharucoCorners, charucoIds, charucoBoard, imgSize, intrinsic, distCoeffsCharuco, rvecs, tvecs, calibrationFlags);
System.out.println("reprojection error : " + repError);
}
I then simply execute the captureImagesCharuco() in the main program. However when I do so I get the following error :
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.UnsatisfiedLinkError: application.DetectorParameters.create_0()J
at application.DetectorParameters.create_0(Native Method)
at application.DetectorParameters.create(DetectorParameters.java:24)
at application.CameraCalibrate.captureImagesCharuco(CameraCalibrate.java:115)
at application.Main.main(Main.java:64)
... 11 more
Exception running application application.Main
I have tried searching for how to solve this error (UnsatisfiedLinkError) and I found that it is usually caused when you're using a library that isn't included in the Build Path or the project (Even though I ma not sure). I guess the library in question here is the Aruco package but I don't know how I can include a package in the build path of the project.
Any kind of help will be more than welcome ! Thank you ! :)
The error indicates that you have opencv package without special module you're using;
In order to fix that you'd need to either find a prebuilt opencv with module you need (in your exactly case it's lcoated in contrib library, so this probably helps.
In case you want to build it from sources - you should enable the module you want in cmake properties. For contrib - you'd need to cmake contrib project first & then enable contrib in main opencv makefile. For building opencv & contirb - please follow official documentation.
Ok I'll try and keep this short.
First let me explain exactly what I am trying to get. If you open Windows Explorer and go to a network drive there is a DFS tab there(must have DFS enabled VIA the servers on the network so it may not be there).
In that tab there is a list called the "Referral List"... I want what is in that box. I believe this is the DFS or UNC, you can correct me it will help me.
What I have is the \domainname.com\something$\BUS\blah\myDriveHome but this is tied to something else in that box that contains the actual server that that share is setting on and that share is what I need to run a compliance check.
I cannot use an exe that is not package with Windows 7 not any other exe as we cannot distribute exes.
So what have I done... a VERY thorough search for things like DFS/UNC paths from the command line, powershell, and registry and no go. Command line "net use" only return the linked path and not the server so that is useless.
I only ever post a question when I hit a wall that is taking up to much programming time.
If anyone has an info it would be grateful.
Thanks
I was able to steal the C# code in this answer here and make some modifications so it works with .Net 2.0, and use it within PowerShell:
$dfsCode = #'
using System;
using System.Runtime.InteropServices;
public static class Dfs
{
private enum NetDfsInfoLevel
{
DfsInfo1 = 1,
DfsInfo2 = 2,
DfsInfo3 = 3,
DfsInfo4 = 4,
DfsInfo5 = 5,
DfsInfo6 = 6,
DfsInfo7 = 7,
DfsInfo8 = 8,
DfsInfo9 = 9,
DfsInfo50 = 50,
DfsInfo100 = 100,
DfsInfo150 = 150,
}
[DllImport("netapi32.dll", SetLastError = true)]
private static extern int NetApiBufferFree(IntPtr buffer);
[DllImport("Netapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
private static extern int NetDfsGetInfo(
[MarshalAs(UnmanagedType.LPWStr)] string DfsEntryPath, // DFS entry path for the volume
[MarshalAs(UnmanagedType.LPWStr)] string ServerName, // This parameter is currently ignored and should be NULL
[MarshalAs(UnmanagedType.LPWStr)] string ShareName, // This parameter is currently ignored and should be NULL.
NetDfsInfoLevel Level, // Level of information requested
out IntPtr Buffer // API allocates and returns buffer with requested info
);
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
private struct DFS_INFO_3
{
[MarshalAs(UnmanagedType.LPWStr)]
public string EntryPath;
[MarshalAs(UnmanagedType.LPWStr)]
public string Comment;
public int State;
public int NumberOfStorages;
public IntPtr Storage;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
private struct DFS_STORAGE_INFO
{
public int State;
[MarshalAs(UnmanagedType.LPWStr)]
public string ServerName;
[MarshalAs(UnmanagedType.LPWStr)]
public string ShareName;
}
private static T GetStruct<T>(IntPtr buffer, int offset)where T:struct
{
T r = new T();
r = (T) Marshal.PtrToStructure((IntPtr)((long)buffer + offset * Marshal.SizeOf(r)), typeof(T));
return r;
}
public static string GetDfsInfo(string server)
{
string rval = null;
IntPtr b;
int r = NetDfsGetInfo(server, null, null, NetDfsInfoLevel.DfsInfo3, out b);
if(r != 0)
{
NetApiBufferFree(b);
// return passed string if not DFS
return rval;
}
DFS_INFO_3 sRes = GetStruct<DFS_INFO_3>(b,0);
if(sRes.NumberOfStorages > 0)
{
DFS_STORAGE_INFO sResInfo = GetStruct<DFS_STORAGE_INFO>(sRes.Storage,0);
rval = string.Concat(#"\\", sResInfo.ServerName, #"\", sResInfo.ShareName, #"\");
}
NetApiBufferFree(b);
return rval;
}
}
'#
Add-Type -TypeDefinition $dfsCode
[Dfs]::GetDfsInfo('\\ad.domain.com\Share')
This code will work with PowerShell 2.0 which is included with Windows 7.
I went another direction with the use of PSEXEC and DFSUtil to find the DFS info VIA the remote PC. Returns a lot of info but I filtered it in PowerShell after reading the file and matching the UNC. I would post the how to but I had to do some major adapting on my end with the info that is on a few other sites for DFSUtil and what to look for and PSExec. I will note this for PSEXEC:
cmd.exe /s /c C:\Temp\psexec.exe 2> $null
That "2> $null" will save you some headaches and your script crashing if the return is in the error channel. You will need to run it in the PS console though without that to catch the error, but when you have a script like mine performing 50+ system checks you don't want the whole thing to halt for just one error.
To reduce the noise in an image, I am trying to get the average of 10 images.
Mat imgMain = new Mat(n_height, n_width, CvType.CV_32FC4);
Mat imgFin = new Mat(n_height, n_width, CvType.CV_32FC4);
for(int i=1; i <= 10; i++) {
//Crop the image
image.recycle();
image = null;
image = BitmapFactory.decodeFile("/storage/sdcard0/DCIM/A" + String.valueOf(i) + ".jpg");
pimage = Bitmap.createBitmap(image, leftOff1, topOff1, n_width, n_height);
Utils.bitmapToMat(pimage, imgMain);
scaleAdd(imgMain, 0.1, imgFin, imgFin);
}
Running the application, I get the following msg:
Caused by: CvException [org.opencv.core.CvException: cv::Exception:
/hdd2/buildbot/slaves/slave_ardbeg1/50-SDK/opencv/modules/core/src/matmul.cpp:2079:
error: (-215) src1.type() == src2.type() in function void
cv::scaleAdd(cv::InputArray, double, cv::InputArray, cv::OutputArray)
]
at org.opencv.core.Core.scaleAdd_0(Native Method)
at org.opencv.core.Core.scaleAdd(Core.java:6690)
at MainActivity.imageAnalysis(MainActivity.java:123)
where line 123 is scaleAdd(imgMaing, 0.1, imgFin, imgFin);
According to the reference, src1, src2 and dst MAT should be of same size and type. However, I get this error when I set imgFin type to 32FC4 but do not get any errors when imgFin is set to 8UC4. Any experience of this kind? I need to keep the floating numbers in imgFin which is why I can't go with 8UC4.
// this line will overwrite your imgMain,
// the type will be CV_8UC4, regardless, what you said before.
Utils.bitmapToMat(pimage, imgMain);
// so, convert to float:
imgMain.convertTo(imgMain, CvType.CV_32FC4);
// now add float images, to avoid precision loss:
scaleAdd(imgMain, 0.1, imgFin, imgFin);
I'm trying to make quite simple game, you're just wandering in rooms, when you use the door you get to other room.
Here's how it looks
i use this simple if to change
if(input.isKeyDown(Input.KEY_UP)) {
sprite = up;
if(!isBlocked(x,y - delta * 0.1f) && y > 0) {
sprite.update(delta); // lower delta = lower speed animation
y -= delta * 0.1f;
}
if(isDoor(x,y - delta * 0.1f)) {
currentMap = currentRoom.getNorth().getMap();
currentRoom = currentRoom.getNorth();
}
}
"currentMap" is TiledMap which currently is being rendered. "currentRoom" is current Room who has TiledMap inside it, because i need some more stuff to store about room. And the problem is that when i go to door, game immediately shuts down with null pointer, however before crashing i can see a glimpse that map is changed.
Full error report:
ERROR:null
java.lang.NullPointerException
at not.zuul.world.GameMain.update(GameMain.java:143)
at org.newdawn.slick.GameContainer.updateAndRender(GameContainer.java:663)
at org.newdawn.slick.AppGameContainer.gameLoop(AppGameContainer.java:411)
at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:321)
at not.zuul.world.GameMain.main(GameMain.java:40)
Sat Oct 25 21:18:51 CEST 2014 ERROR:Game.update() failure - check the game code.
org.newdawn.slick.SlickException: Game.update() failure - check the game code.
at org.newdawn.slick.GameContainer.updateAndRender(GameContainer.java:669)
at org.newdawn.slick.AppGameContainer.gameLoop(AppGameContainer.java:411)
at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:321)
at not.zuul.world.GameMain.main(GameMain.java:40)
Some additional code, these are called on init. Rooms - hashmap of strings containing letter for what direction doors it has (key) , and tiledmap for value ( there 15 diferrent rooms because of diferrent door combinations.
And game_map is again hashmap with String (name) for key and class Room for value. and i use "setRooms" to set "neighbour" for that room, or in other where those doors leads, order is (north, south, east, west)
public void initAllRooms() throws SlickException {
rooms = new HashMap<String, TiledMap>();
rooms.put("N", new TiledMap("resources/map/Rooms/room_north.tmx"));
rooms.put("S", new TiledMap("resources/map/Rooms/room_south.tmx"));
rooms.put("E", new TiledMap("resources/map/Rooms/room_east.tmx"));
rooms.put("W", new TiledMap("resources/map/Rooms/room_west.tmx"));
rooms.put("NE", new TiledMap("resources/map/Rooms/room_north_east.tmx"));
rooms.put("NS", new TiledMap("resources/map/Rooms/room_north_south.tmx"));
rooms.put("NW", new TiledMap("resources/map/Rooms/room_north_west.tmx"));
rooms.put("SE", new TiledMap("resources/map/Rooms/room_south_east.tmx"));
rooms.put("SW", new TiledMap("resources/map/Rooms/room_south_west.tmx"));
rooms.put("EW", new TiledMap("resources/map/Rooms/room_east_west.tmx"));
rooms.put("NSE", new TiledMap("resources/map/Rooms/room_north_south_east.tmx"));
rooms.put("NSW", new TiledMap("resources/map/Rooms/room_north_south_west.tmx"));
rooms.put("NEW", new TiledMap("resources/map/Rooms/room_north_east_west.tmx"));
rooms.put("SEW", new TiledMap("resources/map/Rooms/room_south_east_west.tmx"));
rooms.put("NSEW", new TiledMap("resources/map/Rooms/room_north_south_east_west.tmx"));
}
public void initMap() throws SlickException {
game_map = new HashMap<String, Room>();
game_map.put("outside", new Room(rooms.get("N"), "You're outside."));
game_map.put("mainHall", new Room(rooms.get("NSEW"), "You're in main hall."));
game_map.put("emptyRoom", new Room(rooms.get("NE"), "You're in empty room."));
game_map.put("bathRoom", new Room(rooms.get("S"), "You're in bathroom"));
game_map.put("kitchen", new Room(rooms.get("NW"), "You're in kitchen"));
game_map.put("diningRoom", new Room(rooms.get("NS"), "You;re in dining room"));
game_map.put("backYard", new Room(rooms.get("SE"), "You're in back yard"));
game_map.put("storageRoom", new Room(rooms.get("W"), "You're in storage room"));
game_map.get("outside").setRooms(game_map.get("mainHall"), null, null, null);
game_map.get("mainHall").setRooms(game_map.get("diningRoom"), game_map.get("outside"),
game_map.get("emptyRoom"), game_map.get("kitchen"));
game_map.get("emptyRoom").setRooms(game_map.get("bathRoom"), null, game_map.get("mainHall"), null );
game_map.get("bathRoom").setRooms(null, game_map.get("emptyRoom"), null, null);
game_map.get("kitchen").setRooms(null, null, null, game_map.get("mainHall"));
game_map.get("diningRoom").setRooms(game_map.get("backYard"), game_map.get("mainHall)"), null, null);
game_map.get("backYard").setRooms(null, game_map.get("diningRoom"), game_map.get("storageRoom"), null);
game_map.get("storageRoom").setRooms(null, null, null, game_map.get("backYard"));
}
Can't really help unless you provide the stacktrace and the line(s) the stacktrace is coming from.
EDIT: Still need to see what line the crash is occurring on.
I am beginner in java and Weka tool, I want to use Logitboost algorithm with DecisionStump as weak learner in my java code, but I don't know how do this work. I create a vector with six feature(without label feature) and I want feed it into logitboost for labeling and probability of its assignment. Labels are 1 or -1 and train/test data is in an arff file.This is my code, but algorithm always return 0 !
Thanks
double candidate_similarity(ha_nodes ha , WeightMatrix[][] wm , LogitBoost lgb ,ArrayList<Attribute> atts){
LogitBoost lgb = new LogitBoost();
lgb.buildClassifier(newdata);//newdata is an arff file with some labeled data
Evaluation eval = new Evaluation(newdata);
eval.crossValidateModel(lgb, newdata, 10, new Random(1));
try {
feature_vector[0] = IP_sim(Main.a_new.dip, ha.candidate.dip_cand);
feature_vector[1] = IP_sim(Main.a_new.sip, ha.candidate.sip_cand);
feature_vector[2] = IP_s_d_sim(Main.a_new.sip, ha);
feature_vector[3] = Dport_sim(Main.a_new.dport, ha);
freq_weight(Main.a_new.Atype, ha, freq_avg, weight_avg , wm);
feature_vector[4] = weight_avg;
feature_vector[5] = freq_avg;
double[] values = new double[]{feature_vector[0],feature_vector[1],feature_vector[2],feature_vector[3],feature_vector[4],feature_vector[5]};
DenseInstance newInst = new DenseInstance(1.0,values);
Instances dataUnlabeled = new Instances("TestInstances", atts, 0);
dataUnlabeled.add(newInst);
dataUnlabeled.setClassIndex(dataUnlabeled.numAttributes() - 1);
double clslable = lgb.classifyInstance(inst);
} catch (Exception ex) {
//Logger.getLogger(Module2.class.getName()).log(Level.SEVERE, null, ex);
}
return clslable;}
Where did this newdata come from? you need to load the file properly to get a correct classification, use this class to load features from the file:
http://weka.sourceforge.net/doc/weka/core/converters/ArffLoader.html
I'm not posting an example code because I use weka with MATLAB, so I dont have examples in Java.