Error in Capturing Frames in JavaCV - javacv

All:
I am running Windows XP (32 Bit) with 32 Bit Java and 32 Bit OpenCV 2.4.3. When I attempt to capture a video frame from an AVI with following code in Eclipse:
import com.googlecode.javacv.FrameGrabber.Exception;
import com.googlecode.javacv.OpenCVFrameGrabber;
public class FrameReader
{
public static void main(String[] args) throws Exception,
InterruptedException
{
OpenCVFrameGrabber grabber = new OpenCVFrameGrabber("hall_gray.avi");
grabber.start();
grabber .release();
return;
}//End method
}//End class
The following error happens:
========================== Start of Error =========================
A fatal error has been detected by the Java Runtime Environment:
EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x77c46fa3, pid=4776, tid=3392
JRE version: 7.0_02-b13
Java VM: Java HotSpot(TM) Client VM (22.0-b10 mixed mode, sharing windows-x86 )
Problematic frame:
C [msvcrt.dll+0x36fa3]
Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
An error report file with more information is saved as:
C:\Java Projects\JavaCVTester\hs_err_pid4776.log
If you would like to submit a bug report, please visit:
http://bugreport.sun.com/bugreport/crash.jsp
The crash happened outside the Java Virtual Machine in native code.
See problematic frame for where to report the bug.
==================== End of Error Message ==================
Could someone help me out on this issue?
Thanks in advance.

Try to reinstall your jre.
Also goto the windows startup & recovery option. Choose "writing debugging option" to "Complete memory dump".

The OpenCVFrameGrabber does not support many video formats. The error message "[...] Problematic frame: C [msvcrt.dll+0x36fa3] [...]" probably points out, that your video format may not be supported.
The FFmpegFrameGrabber is more flexible. Try the following code:
import com.googlecode.javacv.FFmpegFrameGrabber;
import com.googlecode.javacv.FrameGrabber;
import com.googlecode.javacv.FrameGrabber.Exception;
public class FrameReader {
public static void main(String[] args) throws Exception {
FrameGrabber grabber = new FFmpegFrameGrabber("hall_gray.avi");
grabber.start();
grabber.release();
return;
}
}

In JavaCV, you can use FFmpegFrameGrabber which is a wrapper of OpenCVFrameGrabber and it has a lot of methods rather than OpenCVFrameGrabber.
Try the following code to extract and save the frames from the video:
import java.io.File;
import com.googlecode.javacv.FFmpegFrameGrabber;
import com.googlecode.javacv.Frame;
import com.googlecode.javacv.cpp.opencv_core.IplImage;
import static com.googlecode.javacv.cpp.opencv_highgui.cvSaveImage;
public class Getting_Frames
{
public static void main(String[] args) throws Exception
{
File f = new File("example.avi");
FFmpegFrameGrabber grabber = new FFmpegFrameGrabber(f);
try {
grabber.start();
} catch (com.googlecode.javacv.FrameGrabber.Exception e1) {
}
long frameLength = grabber.getLengthInFrames();
int increment = (int) Math.ceil(frameLength / 30);
if (frameLength < 30) {
System.err.println("Not enough frames");
}
// To grab frames per 30 seconds
Frame[] s_frame = new Frame[1000];
for (int i=0, frame_counter = 0; i < frameLength; frame_counter++) {
if((frame_counter % 2000 )==0)
{
s_frame[i]=grabber.grabKeyFrame();
IplImage temp = s_frame[i].image;
System.out.println(temp.nChannels()+" "+temp.origin()+" "+temp.highValue());
cvSaveImage(i+"new.jpg",temp);
i++;
}
}
// To know number for each video
System.out.println(frameLength);
}
}

Related

Reading objects from memory with MDbgEng

I wanted to help out #mark in a question where he is asking for an API to dump many objects from a .NET crash dump file.
So I wrote the following code using mdbgeng, but unfortunately it fails with a NotImplementedException when trying to enumerate the objects in memory.
using System;
using System.Runtime.InteropServices;
using Microsoft.Samples.Debugging.CorDebug;
using Microsoft.Samples.Debugging.CorDebug.Utility;
using Microsoft.Samples.Debugging.MdbgEngine;
using Microsoft.Samples.Debugging.Native;
namespace DumpHeapFromDotNet
{
class Program
{
static void Main(string[] args)
{
var libraryProvider = new LibraryProvider();
var dumpReader = new DumpReader(args[0]);
var dataTarget = new DumpDataTarget(dumpReader);
foreach (var module in dumpReader.EnumerateModules())
{
var clrDebugging = new CLRDebugging();
Version actualVersion;
ClrDebuggingProcessFlags flags;
CorProcess proc;
var hr = (HResult) clrDebugging.TryOpenVirtualProcess(module.BaseAddress, dataTarget, libraryProvider,
new Version(4, 6, int.MaxValue, int.MaxValue), out actualVersion, out flags, out proc);
if (hr < 0)
{
switch (hr)
{
case HResult.CORDBG_E_NOT_CLR:
Console.WriteLine(module.FullName + " is not a .NET module");
break;
case HResult.CORDBG_E_LIBRARY_PROVIDER_ERROR:
Console.WriteLine(module.FullName + " could not provide library");
break;
case HResult.CORDBG_E_UNSUPPORTED_DEBUGGING_MODEL:
case HResult.CORDBG_E_UNSUPPORTED_FORWARD_COMPAT:
break;
default:
Marshal.ThrowExceptionForHR((int)hr);
break;
}
}
else
{
var objects = proc.Objects; // NotImplementedException
foreach (CorObjectValue o in objects)
{
// TODO: Write details of object to file here
}
}
}
Console.ReadLine();
}
}
}
The dump I was using is a .NET 4.6.1076.0 dump with full memory (you can pass a file name as an argument):
0:000> lm vm clr
[...]
ProductVersion: 4.6.1076.0
FileVersion: 4.6.1076.0 built by: NETFXREL3STAGE
0:000> .dumpdebug
----- User Mini Dump Analysis
MINIDUMP_HEADER:
Version A793 (61B1)
NumberOfStreams 11
Flags 1806
0002 MiniDumpWithFullMemory
0004 MiniDumpWithHandleData
0800 MiniDumpWithFullMemoryInfo
1000 MiniDumpWithThreadInfo
I doubt it has something to do with missing mscordacwks or similar, since I just created the dump on the same machine with the same .NET framework as I used for this sample.
Is it really not implemented yet, or am I doing something else wrong?
I'm currently messing with MDBG and I have tried to check the described behavior on real application, not on the dump. I received exatly the same not implemented exception. Looking for the documentation on MSDN I've found the confirmation, that this method is not implemented.

Exception in thread "main" com.jacob.com.ComFailException: Can't co-create object

I'm following this tutorial: http://www.joecolantonio.com/2014/07/02/selenium-autoit-how-to-automate-non-browser-based-functionality/ to automate non-browser applications in Windows.
import java.io.File;
import autoitx4java.AutoItX;
import com.jacob.com.LibraryLoader;
import java.lang.System;
public class CalcTest {
/**
*
* Returns if the JVM is 32 or 64 bit version
*/
public static String jvmBitVersion(){
return System.getProperty("sun.arch.data.model");
}
public static void main(String[] args) throws InterruptedException {
String jacobDllVersionToUse;
if (jvmBitVersion().contains("32")){
jacobDllVersionToUse = "jacob-1.18-x86.dll";
}
else {
jacobDllVersionToUse = "jacob-1.18-x64.dll";
}
File file = new File("lib", jacobDllVersionToUse);
System.setProperty(LibraryLoader.JACOB_DLL_PATH, file.getAbsolutePath());
AutoItX x = new AutoItX();
x.run("calc.exe");
x.winActivate("Calculator");
x.winWaitActive("Calculator");
//Enter 3
x.controlClick("Calculator", "", "133") ;
Thread.sleep(1000);
//Enter +
x.controlClick("Calculator", "", "93") ;
Thread.sleep(1000);
//Enter 3
x.controlClick("Calculator", "", "133") ;
Thread.sleep(1000);
//Enter =
x.controlClick("Calculator", "", "121") ;
}
}
I get the following error:
Exception in thread "main" com.jacob.com.ComFailException: Can't co-create object
at com.jacob.com.Dispatch.createInstanceNative(Native Method)
at com.jacob.com.Dispatch.<init>(Dispatch.java:99)
at com.jacob.activeX.ActiveXComponent.<init>(ActiveXComponent.java:58)
at autoitx4java.AutoItX.<init>(AutoItX.java:181)
at CalcTest.main(CalcTest.java:30)
The tutorial says that I should run regsvr32 C:\install\AutoItX\AutoItX3_x64.dll in cmd but I keep getting the following error:
The module "C:\install\AutoItX\AutoItX3_x64.dll" was loaded but the call to DllRegisterServer failed with error code 0x80070005
I'm not sure what to make of this.
The following solution worked for me:
Copy AutoItX3_x64.dll file. You can find it in C:\Program Files (x86)\AutoIt3\AutoItX.
Paste it in C:\Windows\System32.
Open a cmd prompt, run as administrator. Type regsvr32 AutoItX3_x64.dll and press Enter.
You will get a message prompt as DllRegisterServer in AutoItX3_x64.dll succeeds.
I had to run cmd as an administrator. May as well leave this up. I'm sure someone might find themselves in the same boat one day...
Run as Administrator login in cmd and since you are using 64 bit os ,run it in the path C:\Windows\SysWOW64
and for 32 bit run in path ,C:\Windows\System32
--Swapna Mhatre

Ghostscript giving "Ghostscript conversion Error" after executing correctly for the first time

I am facing a wierd issue when converting a pdf to image.I am executing the conversion code on pdf hover .It works well the first time and then starts giving me "ghostscript conversion error" from the next time.The code that gives the error is given below.
int result = InitAPI(gsInstancePtr, args.Length, args);
It returns an errorcode of -100. The Complete code is as below.
public static void CallAPI(string[] args)
{
// Get a pointer to an instance of the Ghostscript API and run the API with the current arguments
IntPtr gsInstancePtr;
lock (resourceLock)
{
CreateAPIInstance(out gsInstancePtr, IntPtr.Zero);
try
{
int result = InitAPI(gsInstancePtr, args.Length, args);
if (result < 0)
{
throw new ExternalException("Ghostscript conversion error", result);
}
}
finally
{
Cleanup(gsInstancePtr);
}
}
}
/// <summary>
/// Frees up the memory used for the API arguments and clears the Ghostscript API instance
/// </summary>
private static void Cleanup(IntPtr gsInstancePtr)
{
ExitAPI(gsInstancePtr);
DeleteAPIInstance(gsInstancePtr);
}
What am i doing wrong?
Well,the first thin is, you aren't using Ghostscript, at least not directly. Possibly you are using Ghostscript.NET ?
From Ghostscript itself error -100 means a fatal error, additional information may be available on stdout or stderr, you need to capture and report that.

WAV Audio recording for Sphinx-4 fail

I recorded a wav file using Audacity for testing transcriber demo from Sphinx-4, I followed the instruction in this post: Sphinx4 speech recognition trasncribe demo not working accurately for short wav file
especially in this answer:
It must be 16khz 16bit mono little-endian file.
I even reduced the noise afterward. But I get the null error when I try to print the hypothesis which mean there was a problem with my recording:
Loading models...
Exception in thread "main" java.lang.NullPointerException
at transcriber.Transcriber.main(Transcriber.java:41)
Java Result: 1
BUILD SUCCESSFUL (total time: 2 minutes 14 seconds)
Line 41 where I print the hypothesis. what can I do to get it work?
Thanks
Edit:
The code is:
package transcriber;
import java.net.URL;
import edu.cmu.sphinx.api.Configuration;
import edu.cmu.sphinx.api.SpeechResult;
import edu.cmu.sphinx.api.StreamSpeechRecognizer;
import edu.cmu.sphinx.result.WordResult;
/**
*
* #author ha
*/
public class Transcriber {
/**
* #param args the command line arguments
*/
public static void main(String[] args) throws Exception {
System.out.println("Loading models...");
Configuration configuration = new Configuration();
// Load model from the jar
configuration.setAcousticModelPath("resource:/WSJ_8gau_13dCep_16k_40mel_130Hz_6800Hz");
configuration.setDictionaryPath("resource:/WSJ_8gau_13dCep_16k_40mel_130Hz_6800Hz/dict/cmudict.0.6d");
configuration.setLanguageModelPath("models/language/en-us.lm.dmp");
StreamSpeechRecognizer recognizer = new StreamSpeechRecognizer(configuration);
URL audioUrl = new URL("file:WAV/Hello.wav");
recognizer.startRecognition(audioUrl.openStream());
SpeechResult result = recognizer.getResult();
System.out.println(recognizer.getResult().getHypothesis());
while ((result = recognizer.getResult()) != null) {
System.out.format("Hypothesis: %s\n",
result.getHypothesis());
}
System.out.println("Stop Recognition..");
recognizer.stopRecognition();
}
}
Replace
System.out.println(recognizer.getResult().getHypothesis());
with
System.out.println(result.getHypothesis());

How to use/setup TexturePacker2 libgdx

I have a difficulty with texturepacker2 from libgdx. I was trying to create textureAtlas using texturepakcer2 so that I can create animated images. However I could not use
TexturePacker2.process(Input Directory Path", "Output Directory Path", "texture_file");
Because it could not recognize TexturePacker2.
Even thought I import gdx-tool.jar file inside libs and also added libraries through
Project -> Properties -> Java Build Path -> Libraries -> Add jars, it still cannot resolve nor recognize the gdx-tool.jar.
How can I create texture atlas using TexturePakcer2? I heard there is a way to create using nightly-build from libgdx, how can I do it? When I unzip latest nightly-build there were so many jar, but I could only run setup-ui.
There are several ways. I used to take the way of implementing it into my Desktop application. Whenever i start it, the Atlas is generated. (If i changed something in it).
public class Main
{
public static void main(String[] args)
{
LwjglApplicationConfiguration cfg = new LwjglApplicationConfiguration();
cfg.title = "MyApp";
cfg.useGL20 = true;
cfg.fullscreen = false;
// switch for fullscreen
if (cfg.fullscreen)
{
cfg.width = Toolkit.getDefaultToolkit().getScreenSize().width;
cfg.height = Toolkit.getDefaultToolkit().getScreenSize().height;
}
else
{
cfg.width = 1280;
cfg.height = 720;
}
cfg.addIcon("data/appiconWindows.png", FileType.Internal);
// automatic packing of the textures and images and so on
Settings settings = new Settings();
settings.maxWidth = 2048;
settings.maxHeight = 2048;
settings.paddingX = 0;
settings.paddingY = 0;
TexturePacker2.process(settings, "directory with the files",
"output dir", "name of Atlas"); //third is outputdir
new LwjglApplication(new MainClass(), cfg);
}
}
Dont forget to add the tools lib to the Desktop project. gdx-tools.jar From the nightly or the Stable.
Else you can call it with the console. Like this:
java -cp gdx.jar;extensions/gdx-tools/gdx-tools.jar com.badlogic.gdx.tools.texturepacker.TexturePacker inputDir [outputDir] [packFileName]
Use TexturePacker from com.badlogic.gdx.tools.imagepacker.TexturePacker then create a class as below:
public class TextureSetup {
public static void main(String[] args) {
//TexturePacker; using default settings
TexturePacker.Settings packSettings = new TexturePacker.Settings();
TexturePacker.process(packSettings, "input-folder", "output-folder", "textures.pack");
}
}

Resources