簡體   English   中英

使用opencv在Android中裁剪圖像

[英]Cropping image in Android using opencv

我在Android中使用OpenCV 2.3.1。 我需要將圖像裁剪成一半。 我在做的是:

    Mat mIntermediateMat2 = new Mat(frame_height,frame_width,rgba.type);
    mIntermediateMat2 = rgba.clone();
    mIntermediateMat2 = mIntermediateMat2.rowRange(0,frame_height/2);

第三步是完成工作還是我必須添加更多內容? 我在opencv 2.3文檔中看到了Mat :: operator(),但遺憾的是無法在opencv Android包中找到它。

Mat類有一些構造函數,其中一個構造函數采用Mat和ROI(感興趣的區域)。

以下是如何在Android / Java中執行此操作:

Mat uncropped = getUncroppedImage();
Rect roi = new Rect(x, y, width, height);
Mat cropped = new Mat(uncropped, roi);

我總是以這種方式裁剪:

Mat image = ...; // fill it however you want to
Mat crop(image, Rect(0, 0, image.cols, image.rows / 2)); // NOTE: this will only give you a reference to the ROI of the original data

// if you want a copy of the crop do this:
Mat output = crop.clone();

希望有所幫助!

似乎cv :: getRectSubPix做你想要的。 此外,您不必分配超出您需要的空間。 如果裁剪區域沒有在精確像素上對齊,它也會進行必要的插值。

這應該做你想要的。 輸入類型將是輸出類型。

Mat dst;
getRectSubPix(src, Size(src.rows()/2,src.cols()), Point2f(src.rows()/4, src.cols()/2), dst);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM