gpt4 book ai didi

java - 如何使这个 LTI CIVIL 示例代码在 Ubuntu 下运行?

转载 作者:行者123 更新时间:2023-11-30 04:58:29 26 4
gpt4 key购买 nike

我测试了一个基于 LTI CIVIL 库的程序,该程序从网络摄像头拍摄照片并每 2 秒保存一次。该程序在Windows Vista下运行得很好,但在Ubuntu下运行时出现错误:

run:
Exception in thread "main" com.lti.civil.CaptureException:java.lang.UnsatisfiedLinkError: no civil in java.library.path
at com.lti.civil.impl.jni.NativeCaptureSystemFactory.createCaptureSystem(NativeCaptureSystemFactory.java:24)
at emptyroomoperation_final.Camera.main(Camera.java:41)
Caused by: java.lang.UnsatisfiedLinkError: no civil in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1734)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1028)
at com.lti.civil.impl.jni.NativeCaptureSystemFactory.createCaptureSystem(NativeCaptureSystemFactory.java:21)
... 1 more
Java Result: 1

这是代码:

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package emptyroomoperation_final;

import java.awt.image.BufferedImage;
import java.io.FileOutputStream;
import java.util.List;

import com.lti.civil.CaptureDeviceInfo;
import com.lti.civil.CaptureException;
import com.lti.civil.CaptureObserver;
import com.lti.civil.CaptureStream;
import com.lti.civil.CaptureSystem;
import com.lti.civil.CaptureSystemFactory;
import com.lti.civil.DefaultCaptureSystemFactorySingleton;
import com.lti.civil.Image;
import com.lti.civil.VideoFormat;
import com.lti.civil.awt.AWTImageConverter;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageEncoder;
import java.io.File;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
*
* @author Ken Larson
*/
public class Camera
{
static public String s;
static int w=0;
//static File f1 = new File("C:\\Users\\mostafa\\Documents\\NetBeansProjects \\EmptyRoomOperation\\0.jpg") ;
// static File f2 = new File("C:\\Users\\mostafa\\Documents\\NetBeansProjects\\EmptyRoomOperation\\") ;
public static void main(String[] args) throws CaptureException
{
CaptureSystemFactory factory = DefaultCaptureSystemFactorySingleton.instance();
CaptureSystem system = factory.createCaptureSystem();
system.init();
List list = system.getCaptureDeviceInfoList();
for (int i = 0; i < list.size(); ++i)
{
CaptureDeviceInfo info = (CaptureDeviceInfo) list.get(i);

System.out.println("Device ID " + i + ": " + info.getDeviceID());
System.out.println("Description " + i + ": " + info.getDescription());

CaptureStream captureStream = system.openCaptureDeviceStream(info.getDeviceID());

System.out.println("Current format " + videoFormatToString(captureStream.getVideoFormat()));

captureStream.setObserver(new MyCaptureObserver());
System.out.println("Available formats:");
for (VideoFormat format : captureStream.enumVideoFormats())
{
System.out.println(" " + videoFormatToString(format));
}

final int MAX_FORMATS = 2;
int count = 0;
//for (VideoFormat format : captureStream.enumVideoFormats())//not now
VideoFormat format = captureStream.enumVideoFormats().get(0);//alternative of the above
int k=0;

while(k!=10)
{
/*if (count > MAX_FORMATS)
{ System.out.println("Stopping after " + MAX_FORMATS + " formats."); // could be a lot
break;
}*/
System.out.println("Choosing format: " + videoFormatToString(format));
captureStream.setVideoFormat(format);
s = new String(""+w);
// File f2 = new File("C:\\Users\\mostafa\\Documents\\NetBeansProjects\\EmptyRoomOperation\\"+s+".jpg") ;

// f1.
System.out.println("Capturing for 2 seconds...");
captureStream.start();
try
{
Thread.sleep(2000);
}
catch (InterruptedException e)
{
return;
}

captureStream.stop();
/*try {
// Thread.sleep(10000);
} catch (Exception ex) {
Logger.getLogger(Camera.class.getName()).log(Level.SEVERE, null, ex);
}*/
//++count;
w++;
}
System.out.println("disposing stream...");
captureStream.dispose();

}
System.out.println("disposing system...");
system.dispose();
System.out.println("done.");
}

public static String videoFormatToString(VideoFormat f)
{
return "Type=" + formatTypeToString(f.getFormatType()) + " Width=" + f.getWidth() + " Height=" + f.getHeight() + " FPS=" + f.getFPS();
}

private static String formatTypeToString(int f)
{
switch (f)
{
case VideoFormat.RGB24:
return "RGB24";
case VideoFormat.RGB32:
return "RGB32";
default:
return "" + f + " (unknown)";
}
}

}

class MyCaptureObserver implements CaptureObserver
{
public void onError(CaptureStream sender, CaptureException e)
{ System.err.println("onError " + sender);
e.printStackTrace();
}

public void onNewImage(CaptureStream sender, Image image)
{
final BufferedImage bimg;
try
{
final VideoFormat format = image.getFormat();
System.out.println("onNewImage format=" + Camera.videoFormatToString(format) + " length=" + image.getBytes().length);
bimg = AWTImageConverter.toBufferedImage(image);
}
catch (Exception e)
{ e.printStackTrace();
return;
}

// Encode as a JPEG
try
{
FileOutputStream fos = new FileOutputStream(Camera.s+".jpg");
JPEGImageEncoder jpeg = JPEGCodec.createJPEGEncoder(fos);
jpeg.encode(bimg);
fos.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}

注意:这与 LTI CIVIL 附带的测试代码几乎相同,但有一些修改。

据我了解,LTI CIVIL 应该也可以在 Ubuntu 下运行。我怎样才能让这段代码在Ubuntu下运行?

最佳答案

下载并查看文件后,看起来您想要的文件位于 lti-civil/native 目录中。根据您的 Linux 版本,有 linux-amd64 和 linux-x86 两种。现在您可以通过两种方式执行操作,使用 LD_LIBRARY_PATH 是一个环境变量,您可以将其设置为指向您希望 linux 搜索动态库的目录。

建议的另一个选项是执行以下操作。创建/etc/ld.so.conf.d/civil.conf。该文件应该只有一行,其中包含解压或提取 lti-civil/native/linux-xxx/lib*.so 文件的路径。您需要 root 访问权限或 sudo 访问权限才能执行此操作。如果您没有访问权限,请将 LD_LIBRARY_PATH 设置为 lti-civil/native/....,它应该可以工作。

关于java - 如何使这个 LTI CIVIL 示例代码在 Ubuntu 下运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7713067/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com