當前位置: 首頁>>代碼示例>>Java>>正文


Java Mat.empty方法代碼示例

本文整理匯總了Java中org.opencv.core.Mat.empty方法的典型用法代碼示例。如果您正苦於以下問題:Java Mat.empty方法的具體用法?Java Mat.empty怎麽用?Java Mat.empty使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.opencv.core.Mat的用法示例。


在下文中一共展示了Mat.empty方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: analyzeObject

import org.opencv.core.Mat; //導入方法依賴的package包/類
/**
 * Analyzes an object in preparation to search for the object in a frame.
 * <p/>
 * This method should be called in an initialize() method.
 * Calling the analyzeObject method twice will overwrite the previous objectAnalysis.
 * <p/>
 * It is recommended to use a GFTT (Good Features To Track) detector for this phase.
 *
 * @param object Object image
 * @return The object descriptor matrix to be piped into locateObject() later
 */
public ObjectAnalysis analyzeObject(Mat object) throws IllegalArgumentException {
    Mat descriptors = new Mat();
    MatOfKeyPoint keypoints = new MatOfKeyPoint();

    Log.d("FTCVision", "Analyzing object...");

    if (object == null || object.empty()) {
        throw new IllegalArgumentException("Object image cannot be empty!");
    }

    //Detect object keypoints
    detector.detect(object, keypoints);

    //Extract object keypoints
    extractor.compute(object, keypoints, descriptors);

    return new ObjectAnalysis(keypoints, descriptors, object);
}
 
開發者ID:ykarim,項目名稱:FTC2016,代碼行數:30,代碼來源:ObjectDetection.java

示例2: grabFrame

import org.opencv.core.Mat; //導入方法依賴的package包/類
private Mat grabFrame()
{
    Mat frame = new Mat(); // empty mat
    if (cap.isOpened())
    {
        try
        {
            cap.read(frame);
            if (!frame.empty()) process(frame);
        }
        catch(Exception ex)
        {
            System.err.println("Error during image processing.");
        }
    }
    
    return frame;
}
 
開發者ID:Plasmoxy,項目名稱:AquamarineLake,代碼行數:19,代碼來源:Controller.java

示例3: detectMany

import org.opencv.core.Mat; //導入方法依賴的package包/類
/**
 * 
* @Title: detectMany 
* @Description: 檢測多人圖片,返回檢測的人臉區域對象
* @param mImgSRC
* @return
* MatOfRect
 */
public static MatOfRect detectMany(Mat mImgSRC) {
	
	if(mImgSRC.empty()) {
		LOG.info("檢測多人圖片檢測時沒有找到圖片");
		return null;
	}
	// 人臉檢測器文件的所在路徑的文件夾名稱數組
	String [] pathKey = {ServletContextHolder.getOpenCVHaarcascades(), "haarcascade_frontalface_alt.xml"};
	CascadeClassifier cascade = new CascadeClassifier(FileUtils.buildFilePath(pathKey));
	if(cascade.empty()) {
		LOG.info("人臉檢測級聯加載器為null");
		return null;
	}
	// 記錄搜索到的人臉區域
	MatOfRect mOfRect = new MatOfRect();
	// 用於計算縮放比例
	int scaledWidth = mImgSRC.width();
	detectManyObject(mImgSRC, cascade, mOfRect, scaledWidth);
	if(mOfRect.toArray().length <= 0) {
		LOG.info("沒有檢測到人臉...");
		return null;
	}
	return mOfRect;
}
 
開發者ID:IaHehe,項目名稱:classchecks,代碼行數:33,代碼來源:DetectObject.java

示例4: main

import org.opencv.core.Mat; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
	final String input = "D:/workspace/SpotSpotter/src/pers/zylo117/spotspotter/image/4.jpg";
	final String output = "D:/workspace/SpotSpotter/src/pers/zylo117/spotspotter/image/output4.jpg";

	System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
	final Mat in = Imgcodecs.imread(input);
	if (in.empty()) {
		throw new Exception("no file");
	}
	final Mat out = LSD(in);
	Imgcodecs.imwrite(output, out);
}
 
開發者ID:zylo117,項目名稱:SpotSpotter,代碼行數:13,代碼來源:LineDetector.java

示例5: main

import org.opencv.core.Mat; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
	final String input = "D:\\tmp\\5.jpg";
	// final String output =
	// "D:/workspace/SpotSpotter/src/pers/zylo117/spotspotter/image/output2.jpg";
	System.loadLibrary("opencv_java330_64");
	final Mat in = Imgcodecs.imread(input);
	if (in.empty()) {
		throw new Exception("no file");
	}
	final Mat mask = binaryzation_OpenCV(in, 300 * 0.6, true);
	MatView.imshow(mask, "mask");
	// Imgcodecs.imwrite(output, mask);
}
 
開發者ID:zylo117,項目名稱:SpotSpotter,代碼行數:14,代碼來源:Binaryzation.java

示例6: grabFrame

import org.opencv.core.Mat; //導入方法依賴的package包/類
private Mat grabFrame()
{
    // init everything
    Mat frame = new Mat();

    // check if the capture is open
    if (this.capture.isOpened())
    {
        try
        {
            // read the current frame
            this.capture.read(frame);

            // if the frame is not empty, process it
            if (!frame.empty())
            {
                process(frame);
            }

        }
        catch (Exception e)
        {
            // log the error
            System.err.println("Exception during the image elaboration: " + e);
        }
    }

    return frame;
}
 
開發者ID:Plasmoxy,項目名稱:AquamarineLake,代碼行數:30,代碼來源:Controller.java

示例7: grabFrame

import org.opencv.core.Mat; //導入方法依賴的package包/類
private Mat grabFrame() {
    Mat frame = new Mat(); // empty mat
    if (cap.isOpened()) {
        try {
            cap.read(frame);
            if (!frame.empty()) process(frame);
        } catch (Exception ex) {
            System.err.println("Error during image processing.");
        }
    }

    return frame;
}
 
開發者ID:Plasmoxy,項目名稱:AquamarineLake,代碼行數:14,代碼來源:Controller.java

示例8: grabImage

import org.opencv.core.Mat; //導入方法依賴的package包/類
public void grabImage(){
    Mat frame = new Mat();

    //connect
    videoCapture = new VideoCapture(0);
    isOpened = videoCapture.isOpened();
    System.out.println("connected: " + isOpened);
    //setSetting
    videoCapture.set(Videoio.CV_CAP_PROP_FRAME_WIDTH, 1280);
    videoCapture.set(Videoio.CV_CAP_PROP_FRAME_HEIGHT, 720);
    //startGrab
    isSucceed = videoCapture.grab();
    System.out.println("started: " + String.valueOf(isSucceed));
    if ((!isOpened) || (!isSucceed))
        return;
    System.out.println("------- START GRAB -------");

    //Wait for camera starting
    while (true){
        videoCapture.read(frame);
        if (!frame.empty())
            break;
    }

    int frameNo = 0;
    long startSysMillis = System.currentTimeMillis();
    while (frameNo < 1000){
        videoCapture.read(frame);
        frameNo++;
    }
    System.out.println(frameNo + " frames in " + (System.currentTimeMillis() - startSysMillis) + " millis");

    videoCapture.release(); // release device

    System.out.println('\n' + "Done");
}
 
開發者ID:Plasmoxy,項目名稱:AquamarineLake,代碼行數:37,代碼來源:Frames.java

示例9: grabFrame

import org.opencv.core.Mat; //導入方法依賴的package包/類
/**
 * Get a frame from the opened video stream (if any)
 * 
 * @return the {@link Image} to show
 */
private Image grabFrame()
{
	// init everything
	Image imageToShow = null;
	Mat frame = new Mat();
	
	// check if the capture is open
	if (this.capture.isOpened())
	{
		try
		{
			// read the current frame
			this.capture.read(frame);
			
			// if the frame is not empty, process it
			if (!frame.empty())
			{
				// face detection
				this.detectAndDisplay(frame);
				
				// convert the Mat object (OpenCV) to Image (JavaFX)
				imageToShow = mat2Image(frame);
			}
			
		}
		catch (Exception e)
		{
			// log the (full) error
			System.err.println("ERROR: " + e);
		}
	}
	
	return imageToShow;
}
 
開發者ID:MeAnupSarkar,項目名稱:ExoVisix,代碼行數:40,代碼來源:FaceDetectionController.java

示例10: subspaceProject

import org.opencv.core.Mat; //導入方法依賴的package包/類
public static Mat subspaceProject(Mat W, Mat mean, Mat src) {
	int n = src.rows();
	int d = src.cols();
	Mat X = new Mat();
	Mat Y = new Mat();
	src.convertTo(X, W.type());
	if(!mean.empty()) {
		for(int i = 0; i < n; i ++) {
			Mat r_i = X.row(i);
			Core.subtract(r_i, mean.reshape(1, 1), r_i);
		}
	}
	Core.gemm(X, W, 1.0, new Mat(), 0.0, Y);
	return Y;
}
 
開發者ID:IaHehe,項目名稱:classchecks,代碼行數:16,代碼來源:Recognition.java

示例11: subspaceReconstruct

import org.opencv.core.Mat; //導入方法依賴的package包/類
public static Mat subspaceReconstruct(Mat W, Mat mean, Mat src) {
	int n = src.rows();
	int d = src.cols();
	Mat X = new Mat();
	Mat Y = new Mat();
	src.convertTo(Y, W.type());
	Core.gemm(Y, W, 1.0, new Mat(), 0.0, X, 2);
	if(!mean.empty()) {
		for(int i = 0; i < n; i ++) {
			Mat r_i = X.row(i);
			Core.add(r_i, mean.reshape(1, 1), r_i);
		}
	}
	return X;
}
 
開發者ID:IaHehe,項目名稱:classchecks,代碼行數:16,代碼來源:Recognition.java

示例12: cutOutImage

import org.opencv.core.Mat; //導入方法依賴的package包/類
/**
	 * 
	* @Title: cutOutImage 
	* @Description: 以Rect坐標裁剪圖片 
	* @param src
	* @param mOfRect
	* @return
	* List<Mat> 
	 */
	public static List<Mat> cutOutImage(Mat src, MatOfRect mOfRect) {
		
		List<Mat> outs = new ArrayList<Mat>();
		
		if(src.empty() || mOfRect.toArray().length <= 0) {
			return null;
		}
		
		int enlarge = 50; //  將圖片的x,y坐標加大
		for(Rect r : mOfRect.toArray()) {
			int enlargeW = (r.x + enlarge) / r.x;
			int enlargeH = (r.y + enlarge) / r.y;
			r.x -= enlarge;
			r.y -= enlarge;
			r.width += (enlargeW * r.width);
			r.height += (enlargeH * r.height);
			
			// 確定人臉在圖像中的整個邊界,防止人臉在邊框之外
			if (r.x < 0) {
				r.x = 0;
			}
			if (r.y < 0) {
				r.y = 0;
			}
			if (r.x + r.width > src.cols()) {
				r.x = src.cols() - r.width;
			}
			if (r.y + r.height > src.rows()) {
				r.y = src.rows() - r.height;
			}
		
			
			Mat cutting = new Mat(src, r); // 裁剪圖片
//			System.out.println(cutting);
			outs.add(cutting);
		}
		return outs;
	}
 
開發者ID:IaHehe,項目名稱:classchecks,代碼行數:48,代碼來源:ImgprocessUtils.java


注:本文中的org.opencv.core.Mat.empty方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。