gpt4 book ai didi

java - 相机图像处理

转载 作者:搜寻专家 更新时间:2023-10-31 20:22:30 24 4
gpt4 key购买 nike

基本上我有一个摄像头芯片(摄像头模块:C3038,使用 OmniVision 的 CMOS 图像传感器 OV6630)通过 RS232 链路连接到 PC。我想在 Java 程序中读取这种格式的图像数据(根据相机规范):

数据格式——YCrCb 4:2:2、GRB 4:2:2、RGB 原始数据

关于如何操作的任何提示?

我的实现:

import gnu.io.CommPortIdentifier;
import gnu.io.PortInUseException;
import gnu.io.SerialPort;
import gnu.io.SerialPortEvent;
import gnu.io.SerialPortEventListener;
import gnu.io.UnsupportedCommOperationException;

import java.awt.*;
import java.awt.image.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
import javax.imageio.*;

public class SimpleRead1 implements Runnable, SerialPortEventListener {
static CommPortIdentifier portId;
static Enumeration portList;

InputStream inputStream;
SerialPort serialPort;
Thread readThread;
byte [] readBuffer;
static byte [] storeBuffer;

public SimpleRead1() {
try {
serialPort = (SerialPort) portId.open("SimpleReadApp", 2000);
}catch (PortInUseException e) {System.out.println(e);}

try {
inputStream = serialPort.getInputStream();
}catch (IOException e) {System.out.println(e);}

try {
serialPort.addEventListener(this);
} catch (TooManyListenersException e) {System.out.println(e);}

serialPort.notifyOnDataAvailable(true);

try {
serialPort.setSerialPortParams(9600,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
} catch (UnsupportedCommOperationException e) {System.out.println(e);}

readThread = new Thread(this);
readThread.start();
}

public void run() {
try {
Thread.sleep(20000);
} catch (InterruptedException e) {System.out.println(e);}
}

@Override
public void serialEvent(SerialPortEvent event){
switch(event.getEventType()) {
case SerialPortEvent.BI:
case SerialPortEvent.OE:
case SerialPortEvent.FE:
case SerialPortEvent.PE:
case SerialPortEvent.CD:
case SerialPortEvent.CTS:
case SerialPortEvent.DSR:
case SerialPortEvent.RI:
case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
break;
case SerialPortEvent.DATA_AVAILABLE:
readBuffer = new byte[Integer.MAX_VALUE];

try {
while (inputStream.available() > 0) {

int numBytes = inputStream.read(readBuffer);
System.out.print(new String(readBuffer));
}
} catch (IOException e) {e.printStackTrace();}

InputStream in = new ByteArrayInputStream(readBuffer);
BufferedImage image = null;

try {
image = ImageIO.read(in);
} catch (IOException e) {e.printStackTrace();}

//GUI for displaying image
ImageIcon imageIcon = new ImageIcon(image);
JLabel label = new JLabel();
label.setIcon(imageIcon);
JFrame frame = new JFrame("image display");
frame.getContentPane().add(label,BorderLayout.CENTER);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
break;
}
}

public static void main(String[] args) throws Exception {
portList = CommPortIdentifier.getPortIdentifiers();

while (portList.hasMoreElements()) {
portId = (CommPortIdentifier) portList.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
if (portId.getName().equals("COM7")) {
// if (portId.getName().equals("/dev/term/a")) {
SimpleRead1 reader = new SimpleRead1();
}
}
}
}
}

最佳答案

不幸的是,Java 本身不支持串行端口——为此您需要一个外部库。我建议看看 the RXTX library ,这似乎是如今的事实标准。

视频传感器芯片本身通常具有相对简单的通信接口(interface)(即没有桥接芯片)。通常它归结为设置图像参数,启动实际的图像数据传输,然后将一些字节读入缓冲区。有时可能涉及图像数据开始或结束签名,但仅此而已。

如果手边有芯片的所有文档,应该不会难 - 我偶尔会在没有任何文档的情况下用 C 做类似的事情...

编辑:

将图像读取为字节数组后,您可以使用 the BufferedImage class使其可用于 Java。也就是说,我无法确定 Java 是否支持 ARGB 变体以外的任何东西——如果你想使用非-传感器中的 RGB 模式。

关于java - 相机图像处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10151822/

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