0
我在OpenCV中編寫了一個簡單的應用程序,用於刪除圖像的黑色背景並以JPG格式保存爲白色背景。但是,它始終以黑色背景保存。無法保存JPG格式的圖像,白色背景OpenCV
這是我的代碼:
Mat Imgsrc = imread("../temp/temp1.jpg",1) ;
mat dest;
Mat temp, thr;
cvtColor(Imgsrc, temp, COLOR_BGR2GRAY);
threshold(temp,thr, 0, 255, THRESH_BINARY);
Mat rgb[3];
split(Imgsrc,rgb);
Mat rgba[4] = { rgb[0],rgb[1],rgb[2],thr };
merge(rgba,4,dest);
imwrite("../temp/r5.jpg", dest);
其保存爲PNG,因爲JPEG圖像不支持透明度。 –
謝謝,但我不想透明我想要白色 – mahdi101
請附上樣品輸入和預期的輸出以及 – ZdaR