0
我試圖在圖像中灰化所有人的面孔。雖然我可以檢測到他們的臉並將它們灰成較小的墊子,但我無法將灰色的臉部「複製」到原始墊子上。這樣最終的結果將會有一張灰色的臉。OpenCV檢測投資回報率,創建子圖並複製到原始圖塊
faceDetector.detectMultiScale(mat, faceDetections);
for (Rect rect : faceDetections.toArray())
{
Rect rectCrop = new Rect(rect.x, rect.y, rect.width, rect.height);
Mat imageROI = new Mat(mat,rectCrop);
//convert to B&W
Imgproc.cvtColor(imageROI, imageROI, Imgproc.COLOR_RGB2GRAY);
//Uncomment below will grayout the faces (one by one) but my objective is to have them grayed out on the original mat only.
//Highgui.imwrite(JTestUtil.DESKTOP_PATH+"cropImage_"+(++index)+".jpg",imageROI);
//add to mat? doesn't do anything :-(
mat.copyTo(imageROI);
}
感謝@Vasanth的答案。給定一幅面部圖像,我的目標是將圖像中的所有面轉換爲B&W。在我的代碼中,我能夠逐個轉換面部(如圖像),但無法將它們全部放在原始圖像中。再次感謝! (我認爲問題出在你寫的頻道的某個地方) – adhg
如果它解決了你的問題,請接受它。可能對別人也有用:)。 – Vasanth