1
我建立在C變化檢測一個代碼++使用的OpenCV但是建立它這代碼顯示運行時錯誤如果我改變圖像opencv的錯誤,同時用C++
void MainWindow::on_pushButton_2_clicked()
{
cv::Mat input1 = cv::imread("C:\\Users\\trainee2017233\\Desktop\\pre-post\\sulamani_ms1p1_pre_gref.tif");
cv::Mat input2 = cv::imread("C:\\Users\\trainee2017233\\Desktop\\post-post\\sulamani_ms1p1_pre_gref.tif");
cv::Mat diff;
cv::absdiff(input1, input2, diff);
cv::Mat diff1Channel;
// WARNING: this will weight channels differently! - instead you might want some different metric here. e.g. (R+B+G)/3 or MAX(R,G,B)
cv::cvtColor(diff, diff1Channel, CV_BGR2GRAY);
float threshold = 30; // pixel may differ only up to "threshold" to count as being "similar"
cv::Mat mask = diff1Channel < threshold;
cv::imshow("similar in both images" , mask);
// use similar regions in new image: Use black as background
cv::Mat similarRegions(input1.size(), input1.type(), cv::Scalar::all(0));
// copy masked area
input1.copyTo(similarRegions, mask);
cv::imshow("input1", input1);
cv::imshow("input2", input2);
cv::imshow("similar regions", similarRegions);
cv::imwrite("../outputData/Similar_result.png", similarRegions);
cv::waitKey(0);
}
當我寫兩個圖像作爲相同圖像則沒有錯誤是存在的,但同時,他們更換不同的圖像則顯示錯誤
OpenCV Error: Sizes of input arguments do not match (The operation is neither 'array op array' (where arrays have the same size and the same number of channels), nor 'array op scalar', nor 'scalar op array') in arithm_op, file D:\opencv\sources\modules\core\src\arithm.cpp, line 659
在我的代碼中添加此行後閃爍新錯誤** OpenCV錯誤:斷言失敗(dsize.area()> 0 || (inv_scale_x> 0 && inv_scale_y> 0))調整大小,文件D:\ opencv \ sources \ modules \ imgproc \ src \ imgwarp.cpp,第3484行** –
由於圖片讀取失敗,出現此錯誤,請確保' input1'和'input2'不是空數組。 –
不,它們不是空的。我想再問一個問題,如果我想讀取.tif文件,並且因爲它們的大尺寸imread函數不支持這些類型的文件,所以我切換到libtiff庫並且我得到很多錯誤,請你告訴我在C++ + –