When i open a image, why does it has a border? [closed]

asked Dec 24 '15

source image

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);

``` result image

I can't understand this situration,Where is the problem?

Preview: (hide)

Closed for the following reason the question is answered, right answer was accepted by sturkmen
close date 2020-10-11 15:15:31.474130

Comments

1

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)

berak gravatar imageberak (Dec 24 '15)edit

I tested that your said,but the result is the same

FreeApe gravatar imageFreeApe (Dec 24 '15)edit

@berak,and the value of IMERAD_ANYCOLOR can't be find ,though i konw the value is 4

FreeApe gravatar imageFreeApe (Dec 24 '15)edit

cv::IMREAD_UNCHANGED (or just -1) , sorry, got it wrong

berak gravatar imageberak (Dec 24 '15)edit

THanks.^_^ How to judge whether the image has an alpha channel?

FreeApe gravatar imageFreeApe (Dec 24 '15)edit

cerr << image.type() << " " << image.channels();

[24 4]

berak gravatar imageberak (Dec 24 '15)edit

...The channels is related to the second pram of imread() function

FreeApe gravatar imageFreeApe (Dec 24 '15)edit

... 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.

berak gravatar imageberak (Dec 25 '15)edit