본문 바로가기

Programming

How to get image from usb camera using OpenCV in Java, 자바 openCV 이용하여 usb 카메라에서 이미지 저장, c++,영상처리,imageProcessing

How to get image from usb camera/webcam using OpenCV in Java, 자바 openCV 이용하여 usb 카메라에서 이미지 저장, c++,영상처리,imageProcessing



보드와 연결된 카메라에서 OpenCV를 이용하여 이미지 캡처~




 단일 이미지 외에 여러 프레임으로 쭉 이어지는 실시간 영상 출력 방법 ( 여기 ) - 아직



//처리과정

//1. VideoCapture 객체를 만들어 카메라와 연결해준다.

//2. 만든 객체에서 카메라 세팅을 설정한다.

//3. 찍는다.

//4. 다 끝나면 할당해제


//Process

//1. Make VideoCapture object and connect to usb camera

//2. Set camera param to the object if you need

//3. Take image

//4. Release all





Code.. lemme see code

코드.. 코드를 보자




public class CameraECon /*extends ICamera*/ {


protected VideoCapture capture;

protected Mat frame;



public void execCameraTest() {

// video test

// this.test();

if (this.capture == null)

this.connect();

if (this.isConnected())

{

//this.setting(new SettingCameraECon());

this.shoot();

this.saveFrame();

this.disconnect();

}

}

@Override

public boolean connect() {

        this.capture = new VideoCapture();

        this.capture.open(0);


        if (this.capture.isOpened())

        return true;

        else

        return false;

}

@Override

public void disconnect() {

if (this.capture.isOpened())

this.capture.release();

this.capture = null;

if (!this.frame.empty())

this.frame.release();

this.frame = null;

}


@Override

public void shoot() {

if (this.frame == null)

this.frame = new Mat((int)this.capture.get(Videoio.CV_CAP_PROP_FRAME_WIDTH),

(int)this.capture.get(Videoio.CV_CAP_PROP_FRAME_WIDTH),

CvType.CV_8S);

this.capture.read(frame);

}


@Override

public boolean isConnected() {

return capture.isOpened();

}


public void saveFrame() {

if (this.frame != null)

MatUtils.saveMatImage(this.frame, "testCam/test.png"); // 경로

}

}



//Util class

public class MatUtils

{

public static void saveMatImage(final Mat src, String savePath) {

Core.normalize(src, src, 0, 255, Core.NORM_MINMAX);

//TODO change save path,

if (savePath == null) 

savePath = "D:\My\Desktop\test.png";

Imgcodecs.imwrite(savePath, src);

}

}





Something else you might like...?




2019/01/16 - [Computer/General] - Path/Location of temporary files in each OS, 운영체제별 임시파일 저장 경로/위치


2019/01/15 - [Programming/Java] - How to setup/install Oracle Java OpenJDK with OpenJFX and Eclipse IDE, whole development environment. 오라클 자바 OpenJDK, OpenJFX, Eclipse 전체 개발환경 설치 방법 / javafx, ojdk, ojfx, sceneBuilder


2018/12/28 - [Programming/Software Architecture] - Perfecting OO's Small Classes and Short Methods. 완벽한 객체지향의 작은 클래스와 짧은 메소드, Book:ThoughtWorks Anthology, Java,cpp,자바,oop,좋은코드,객체지향프로그래밍 - (#9, Tell, Don't Ask)

2018/12/26 - [Programming/Software Architecture] - Perfecting OO's Small Classes and Short Methods. 완벽한 객체지향의 작은 클래스와 짧은 메소드, Book:ThoughtWorks Anthology, Java,cpp,자바,oop,좋은코드,객체지향프로그래밍 (1)



2019/01/12 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #60 sudoku. Algorithm,알고리즘,Codefights,CodeSignal,코드파이트,코드시그널,예제,문제해결능력,example,c++,java,재귀,recursive

2019/01/12 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #59 spiralNumbers. Algorithm,알고리즘,Codefights,CodeSignal,코드파이트,코드시그널,예제,문제해결능력,example,c++,java,재귀,recursive

2019/01/08 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #58 messageFromBinaryCode. Algorithm,알고리즘,Codefights,CodeSignal,코드파이트,코드시그널,예제,문제해결능력,example,c++,java,재귀,recursive

2019/01/07 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #57 fileNaming. Algorithm,알고리즘,Codefights,CodeSignal,코드파이트,코드시그널,예제,문제해결능력,example,c++,java,재귀,recursive



2019/01/04 - [Life/Health care] - Omega-3 오메가3 usage/side effects/dosage/fatigue/supplement,효능/부작용/성인,소아 용법/건강/피로회복/영양제

2019/01/08 - [Life/Health care] - VitaminD 비타민디 usage/side effects/dosage/fatigue/supplement/antioxidant/효능/부작용/성인,소아 용법/건강/피로회복/영양제/항산화

2019/01/17 - [Life/Health care] - Zinc 아연 usage/side effects/dosage/fatigue/supplement/antioxidant/효능/부작용/성인,소아 용법/건강/피로회복/영양제/항산화