When i open a image, why does it has a border? [closed]
QString fileName = QFileDialog::getOpenFileName(this,
tr("Open Image"),".",
tr("Image Files(*.png *.jpg *.jpeg *.bmp)"));
image = cv::imread(fileName.toUtf8().data());
if(!image.data){
qDebug()<< "Could not open or find the image";
return ;
}
QString status = QString::number(image.rows) + "x" + QString::number(image.cols);
ui->label_2->setText(status);
//show
cv::namedWindow("Original Image");
cv::imshow("Original Image",image);
```
your png has an alpha channel.
it will "look ok.", if you use:
cv::imread(fileName.toUtf8().data(), IMREAD_ANYCOLOR);
(but again, alpha is quite meaningless in computervision, so rather avoid images like that)
I tested that your said,but the result is the same
@berak,and the value of IMERAD_ANYCOLOR can't be find ,though i konw the value is 4
cv::IMREAD_UNCHANGED
(or just -1) , sorry, got it wrongTHanks.^_^ How to judge whether the image has an alpha channel?
cerr << image.type() << " " << image.channels();
[24 4]
...The channels is related to the second pram of imread() function
... and then - if you use imshow() to watch it, it will still look the same (imshow strips the alpha chan)
in the end, the border is in your image, so if you do any operations on the bgr pixels, it will show up there.
if you're trying to do computervision, maybe better avoid images like that.