首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >摄像机图像处理

摄像机图像处理
EN

Stack Overflow用户
提问于 2012-04-14 15:20:09
回答 2查看 1.2K关注 0票数 5

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

数据格式- YCrCb 4:2:2,GRB4:2:2,RGB原始数据

有什么关于如何做的提示吗?

我的实现:

代码语言:javascript
复制
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();
           }
        }
    }
}
}
EN

回答 2

Stack Overflow用户

发布于 2012-04-14 15:58:44

不幸的是,Java本身并不支持串行端口-您需要一个外部库来支持它。我建议看一看the RXTX library,它现在似乎是一种事实上的标准。

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

如果你手头上有芯片的所有文档,这应该不会太难--我偶尔会在没有任何文档的情况下用C语言做类似的事情。

编辑:

一旦将图像读入字节数组,就可以使用the BufferedImage class使其可用于Java。也就是说,我还不能确定Java是否只支持ARGB变体-如果你想在你的传感器中使用非RGB模式,你可能必须自己进行色彩空间转换(我想是通过第三方库)。

票数 3
EN

Stack Overflow用户

发布于 2012-04-14 15:58:20

这个问题有点宽泛,所以我不知道你有多少经验,但是对于RS-232,你需要使用SerialPort。Here是一个简单的示例,让您开始从COM端口读取数据。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10151822

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档