I am trying to get OpenCV running i am using the following
sample code
I get the following Error line displayed:
OpenCV Error: Assertion failed (!empty()) in cv::CascadeClassifier::detectMultiScale, file ..\..\..\..\opencv\modules\objdetect\src\cascadedetect.cpp, line 1580
Exception in thread "main" CvException [org.opencv.core.CvException: cv::Exception: ..\..\..\..\opencv\modules\objdetect\src\cascadedetect.cpp:1580: error: (-215) !empty() in function cv::CascadeClassifier::detectMultiScale
]
at org.opencv.objdetect.CascadeClassifier.detectMultiScale_1(Native Method)
at org.opencv.objdetect.CascadeClassifier.detectMultiScale(CascadeClassifier.java:176)
at org.maxbit.opencv.samples.DetectFaceDemo.run(SampleB.java:29)
at org.maxbit.opencv.samples.SampleB.main(SampleB.java:51)
Can any body tell me what that error means or how to debug this?
I also faced the problem. The problem is in the .getPath() return an absolute path of the format.
Eg: "/C:/Users/projects/FaceDetection/bin/com/face/detection/haarcascade_frontalface_alt.xml".
So change the code like this.
CascadeClassifier faceDecetor = new CascadeClassifier(FaceDetection.class.getResource("haarcascade_frontalface_alt.xml").getPath().substring(1));
This happens usually for two reasons.
Cascade classifier file lbpcascade_frontalface.xml not present at specified path.
Cascade classifier file is corrupted.
To get an error message instead of exception during runtime, try code sample as below. The CascadeClassifier constructor is silent, if it cannot load the cascade classifier XML. The onus is on the developer to call the empty() method and check if classifier is loaded correctly
CascadeClassifier cascade = new CascadeClassifier( CASCADE_CLASSIFIER_PATH );
if ( cascade.empty() ) {
//handler error here
}
Exception you got is from OpenCV native code assertion here.
I ran into this same error running on a Windows box. This sample runs on linux but not Windows.
The problem is in the .getPath() call after getResource() for both the xml file and the image.
The problem is that the URL.getPath() and the URL.getFile() both return an absolute path of the format "/c:/...".
The OpenCV routines choke on this it must be "c:/..." (no leading '/'). This seems like a bug in the early part of version 3.0.0?
I hope this helps, OpenCV for Java seems like a great tool ... but it is a bit frustrating when the examples don't work.
There is a problem with the latest openCV it doesn't work when you have spaces in your path so do this:
String s =CameraPanel.class.getResource("lbpcascade_frontalface.xml").getPath().substring(1);
String[] split = s.split("%20");
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < split.length-1; i++) {
stringBuilder.append(split[i]+" ");
}
stringBuilder.append(split[split.length-1]);
faceDetector = new CascadeClassifier(stringBuilder.toString());
I ran into the same issue: On windows, OpenCV chokes on both the prepended '\' and any whitespace in the path, as both Imad and Aung have noted. My solution is a bit shorter than Imad's:
Change this:
CascadeClassifier faceDecetor = new CascadeClassifier(
getClass().class.getResource("haarcascade_frontalface_alt.xml").getPath());
To this:
CascadeClassifier faceDecetor = new CascadeClassifier(
getClass().class.getResource("haarcascade_frontalface_alt.xml").getPath().substring(1).replaceAll("%20", " "));
For me the simplest solution was:
private void checkboxSelection(String classifierPath) {
// load the classifier(s)
faceCascade.load(classifierPath);
// Did it work?
if (faceCascade.empty()) {
// Try the full path
String resource = getClass().getResource(classifierPath).getPath();
// Discard leading / if present.
if ( resource.startsWith("/")) {
resource = resource.substring(1);
}
faceCascade.load(resource);
}
// now the video capture can start
cameraButton.setDisable(false);
}
I am using openCv 3.4.1
I think there's a bug in CascadeClassifier initializer.
In order to get rid of this error, I must call "load" once again. Hope this solution could help.
cascadeClassifier = new CascadeClassifier(mCascadeFile.getAbsolutePath());
cascadeClassifier.load(mCascadeFile.getAbsolutePath());
I faced problem on Mac (OSX) Java.
CameraFrame.class.getResource("haarcascade_frontalface_alt.xml").getPath().substring(1)
returned "Users/username/Desktop/JavaProjects/Camera/bin/haarcascade_frontalface_alt.xml".
whereas path should start with "/" therefore I appended "/".
face = new CascadeClassifier("/" +
CameraFrame.class.getResource("haarcascade_frontalface_alt.xml").getPath().substring(1));
It works OK now :)
I faced the same problem as well. It is just because the path you gave for 'haarcascade_frontalface_alt2.xml' might be incorrect of not proper. just copy the full path from file explorer and paste it. This solution works for me.
face_cascade = cv2.CascadeClassifier('C:/Users/xyz/FaceDetect/faceId/OpenCV-Python-Series-master/src/cascades/data/haarcascade_frontalface_alt2.xml')
Related
I'm trying to create an image depicting matches between keypoints in images generated from sift files, using the Features2d.drawMatches method from openCV java API. I can't seem to figure out what kind of argument the method will take as an output parameter - I keep getting the following Assertion Error:
OpenCV(3.4.1) Error: Assertion failed (!outImage.empty()) in
cv::drawKeypoints, file C:\build\master_winpack-bindings-win32-vc14-
static\opencv\modules\features2d\src\draw.cpp, line 115
Exception in thread "main" CvException [org.opencv.core.CvException:
cv::Exception: OpenCV(3.4.1) C:\build\master_winpack-bindings-win32-vc14-
static\opencv\modules\features2d\src\draw.cpp:115: error: (-215)
!outImage.empty() in function cv::drawKeypoints
]
at org.opencv.features2d.Features2d.drawMatches_1(Native Method)
at org.opencv.features2d.Features2d.drawMatches(Features2d.java:71)
at com.company.GUI.ImagesView.matchPoints(ImagesView.java:94)
at com.company.GUI.ImagesView.<init>(ImagesView.java:69)
at com.company.Main.main(Main.java:17)
My code:
private void matchPoints() {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
MatOfKeyPoint matKey1 = new MatOfKeyPoint(keyPoints1);
MatOfKeyPoint matKey2 = new MatOfKeyPoint(keyPoints2);
MatOfDMatch matDMatch = new MatOfDMatch(matches);
Mat output = new Mat();
//output = new Mat(matKey1.rows(), matKey1.cols(), CvType.CV_8U, Scalar.all(0));
if (!output.empty())
System.out.println("not empty");
else
System.out.println("empty");
Features2d.drawMatches(mat1, matKey1, mat2, matKey2, matDMatch, output);
HighGui.imshow("Matches", output);
}
The exact same assertion error shows up whether or not I un-comment the commented line, despite the empty() check below returning different values for these two Mats. I'm at loss, help would be much appreciated.
I can't comment, so I must write an answer:
I had the same problem and somehow solved it. It is no dependency error - I have solved it without changing my dependencies (or imported libraries).
If the matches computed correctly, there won't occure this specific error when calling this function.
In my code, the error was the call of the compute function. I tried to call this function with an FastFeatureDetector - but I somewhere have read that this detector can't find any matches.
Try to compute the
ORB extractor = ORB.create();extractor.compute(currentFrame, keyPoints, imgDescriptor);
When trying to compute the imgDescriptor, no error should occur; after matching you should be able to draw the matches.
Hope, I helped you or anyone else struggling with this kinda error.
When I try to load a file into the asset manager, LibGDX does not seem to pick it up. However, it works perfect on Windows!
I debugged the finishloading() method and It claims the parameter toLoad = 1 but it does not load.
On windows it would say loaded = 1 in the debugging screen.
Code sample:
ParticleEffectLoader.ParticleEffectLoadParameter loadParam = new ParticleEffectLoader.ParticleEffectLoadParameter(particleSystem.getBatches());
ParticleEffectLoader loader = new ParticleEffectLoader(new InternalFileHandleResolver());
Assets.instance.assetManager.setLoader(ParticleEffect.class, loader);
Assets.instance.assetManager.load("bb.pfx", ParticleEffect.class, loadParam);
Assets.instance.assetManager.finishLoading();
effect1=Assets.instance.assetManager.get("bb.pfx",ParticleEffect.class).copy();
The last line fails with a AssetNotLoaded on Android. Filenames are case sensitive, so that is not the error.
com.badlogic.gdx.utils.GdxRuntimeException: Asset not loaded: bb.pfx
at com.badlogic.gdx.assets.AssetManager.get(AssetManager.java:144)
at bvo.games.colorspace.settings.Assets$AssetBillboard.<init>(Assets.java:109)
Does anyone know a solution to this?
My Asset class was static, on Android this does give unexpected results, as Xoppa pointed out in his comment. Problem solved. :)
I am not much familiar with Java but I try to accomplish this task in R (my fav)!
There is this Java library called Jackcess. I want to connect to this library and open an MS Access 2003 .mdb file in it. Jackcess cookbook tells me the first step to using this library is this:
Database db = DatabaseBuilder.open(new File("mydb.mdb"));
or as #Gord suggests,
File file = new File("C:/Users/Public/jackcessTest.mdb");
DatabaseBuilder dbbo = new DatabaseBuilder();
dbbo.setFile(file);
Database db = dbbo.open();
but I'm stuck at this very first step.
I have installed Java and rJava and set up everything about directories.
This is my code in R
library(rJava)
.jinit()
.jaddClassPath("java/jackcess-2.1.2.jar") # there I have put the downloaded jar file of Jackcess
# .jaddClassPath("java/commons-logging-1.2.jar") # this is the commons-logging class that Jackcess depends on, commented to replicate problem 2] in my question.
file.name <- "D:/63.mdb" # some data base .mdb file (containing only tables)
file <- .jnew("java/io/File",file.name)
dbbo <- .jnew("com/healthmarketscience/jackcess/DatabaseBuilder")
[Edit: I found out I had two problems, one solved, one still not.]
up to this part everything is ok, but I have some problems from now on:
1] Correctly calling a method from Jackcess without signature mismatch, neither of these work:
dbbo <- .jcall(dbbo,"L<DatabaseBuilder>","setFile",file)
dbbo <- .jcall(dbbo,"Lcom/healthmarketscience/jackcess/DatabaseBuilder","setFile",file)
I get this error:
Error in .jcall(dbbo, "Lcom/healthmarketscience/jackcess/DatabaseBuilder", :
method setFile with signature (Ljava/io/File;)Lcom/healthmarketscience/jackcess/DatabaseBuilder not found
well I found the answer to this step, I just needed a semicolon (;) at the end of class definition string.
dbbo <- .jcall(dbbo,"Lcom/healthmarketscience/jackcess/DatabaseBuilder;","setFile",file)
2] Calling the open method correctly, my first round of try:
db <- .jcall(dbbo,"Lcom/healthmarketscience/jackcess/Database;","open",evalArray = FALSE,evalString = FALSE)
and I get this error:
Error in .jcall(dbbo, "Lcom/healthmarketscience/jackcess/Database;", "open", :
java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
I googled and found out that Jackcess depends on some library called commons-logging, so downloading and adding it to classpath solves THAT problem
3] Calling the open method correctly, my second round of try: with commons-logging in classpath
db <- .jcall(dbbo,"Lcom/healthmarketscience/jackcess/Database;","open",evalArray = FALSE,evalString = FALSE)
this gives me this error:
Error in .jcall(dbbo, "Lcom/healthmarketscience/jackcess/Database;", "open", :
java.lang.NoClassDefFoundError: Could not initialize class com.healthmarketscience.jackcess.impl.DatabaseImpl
Any Ideas for this error?
[NOTE]: some answers were suggested before my edits, so they may seem irrelevant now, but I have used them in the steps I explained above.
The following code shows an alternate approach in Java using the .setFile and .open methods of a "real" DatabaseBuilder object:
File file = new File("C:/Users/Public/jackcessTest.mdb");
DatabaseBuilder dbbo = new DatabaseBuilder();
dbbo.setFile(file);
Database db = dbbo.open();
Try something similar in rJava and see if it works for you.
Edit re: updated question
You mentioned that you added Apache commons-logging to your CLASSPATH, but Jackcess also relies on Apache commons-lang v2.x (not v3.x), so try downloading that and including it in your CLASSPATH as well.
3 suggestions:
Include commons-lang-2.0.jar in your classPath, similarly to
rJava::.jaddClassPath("commons-lang-2.0.jar")
The easy way is to try calling with J() like so:
dbb <- rJava::.jnew("com/healthmarketscience/jackcess/DatabaseBuilder")
dbjfile <- rJava::.jnew('java/io/File', "D:/63.mdb")
dbop <- rJava::J(dbb, "open", dbjfile)
For what it's worth, if you really want to do it the low-level way, this is one way to try:
dbop <- .jcall(
"RJavaTools"
, "Ljava/lang/Object;"
, "invokeMethod"
, .jcall(dbb, "Ljava/lang/Class;", "getClass")
, .jcast(dbb, "java/lang/Object")
, .jnew("java/lang/String", "open")
, .jarray(list(dbjfile), "java/lang/Object", dispatch = FALSE)
, .jarray(rJava:::._java_class_list(list(dbjfile)), "java/lang/Class", dispatch = FALSE)
, use.true.class = TRUE
, evalString = TRUE
, evalArray = FALSE
)
I created my own new R library (called "Media"). There is no problem when I try to load it with RGui, and I can call the functions defined in the new package. This is how I load it:
> library(Media)
But, I'm also trying to call that functions from Java/JRI code, and when I load the new R package, Java doesn't seem to find the pacakge, throwing the message "Error in library(Media) : object 'Media' not found"
This is my current code using JRI:
REXP rexpSetFolder = re.eval("setwd('C:/Users/Albert/Documents')");
REXP rexpFolder = re.eval("getwd()");
System.out.println(rexpFolder.asString());
REXP rexpLoad = re.eval("library(Media)"); // fails
It also fails without the 'setwd' command, and simple calls to existing R functions work fine. I'm using R 2.10 and the latest JRI 0.5-0 under Windows.
Any help would be appreciated.
Thank you very much.
Edit:
The parameter lib.loc seems to work, at least this sentence does not return an error:
library("Media", lib.loc = "c:/Users/Albert/Documents")
But after that, calling a function in the package with re.eval("myfunction()"); still fails, as the function is not properly found.
You can modify the library path - see ?.libPaths in R, you simply want to add your private library to the path. The GUI does that for you, but if you are outside it doesn't happen. For example:
re.eval(".libPaths('c:/users/foo/Documents/R')");
Then load your package.
Did you install the library properly first? You might want to try using the lib.loc parameter.
library("Media", lib.loc = "c:/Users/Albert/Documents")
My work-around was to copy the package from my personal library (%USERPROFILE%\Documents\R) to the global library (%R_HOME%\library).
It's not the best because this requires Administrator privileges which not all users will have...
i have a grails project with an Image Domain Class and Controller.
I just installed the grails ImageTools 1.0.4 Plugin and i would like to generate thumbnails for images wich will be uploaded.
My Image-Domain-Class:
class Image {
byte[] data
//String name
byte[] thumbnail
static constraints = {
//name()
data()
}
}
The "safe"-action in my Controller:
def save = {
def imageInstance = new Image(params)
def imageTool = new ImageTool()
imageTool.load(imageInstance.data)
imageTool.thumbnail(320)
imageInstance.thumbnail = imageTool.getBytes("JPEG") //Here is my problem!
if(!imageInstance.hasErrors() && imageInstance.save()) {
flash.message = "Image ${imageInstance.id} created"
redirect(action:show,id:imageInstance.id)
}
else {
render(view:'create',model:[imageInstance:imageInstance])
}
}
When I start my Grails-application and uploading an image I'm getting the following error-message:
Error 200: groovy.lang.MissingMethodException: No signature of method: ImageTool.getBytes() is applicable for argument types: (java.lang.String) values: {"JPEG"}
Servlet: grails
URI: /grailsproject/grails/image/save.dispatch
Exception Message: No signature of method: ImageTool.getBytes() is applicable for argument types: (java.lang.String) values: {"JPEG"}
Caused by: groovy.lang.MissingMethodException: No signature of method: ImageTool.getBytes() is applicable for argument types: (java.lang.String) values: {"JPEG"}
Class: GrailsAuthenticationProcessingFilter
At Line: [57]
It says that the Method getBytes() is missing but the method is still available. My IDE intelliJ also recognizes no errors.
So what can I do? Could someone help me please?
Sorry for my bad english. If you are german, please look at http://support-network.info/board/problem-mit-imagetools-getbytes-t3008.html .
I use Grails 1.0.4.
I could fix this error message. I just copied the getBytes() method from the git Repository of Ricardo (the plugin developer) and replaced the old one with the new one. Now everything works! I don't know where the bug was but i'm happy that i solved it.
Thank you both very much!
Looks like that method is a fairly new addition to the class (3/6/2009). If you have verified that that method is in the ./plugins/imagetools/src/groovy/ImageTool.groovy file I'd recommend running:
grails clean
If you had been using this plugin prior it might be a cache problem.
The reply that you received from John sounds about right - if you have installed the new plugin and can see the code, but keep getting this error only outside IntelliJ, you should try cleaning your grails cache - it's very possible that an older copy of the plugin is precompiled on the cache.
Are you using Grails 1.1? I haven't yet tested it with the latest grails, but I understand it keeps the plugins not under the project but in a separate directory. Do let me know and I'll try it out.
I don't know what the plugin is really giving you over using JAI directly, IMHO it isn't doing much.
I use ImageMagick out of process for my image conversion and the results are superior to what can be done with JAI from what I have seen. Of course if your doing as much traffic as Amazon running out of process is not an option, however if you need to get to revenue as quickly as possible then you might want to consider what I've done.
I use apache-commons-exec to have a nice interface around handling opening an external process and reading data from std in and out. The only thing I'm using JAI for is to read the sizes of images.
try this one http://support-network.info/board/gel%C3%B6st-problem-mit-imagetools-getbytes-t3008.html