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

asked 2015-12-23 23:37:37 -0600

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?

edit retag flag offensive reopen merge delete

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 ( 2015-12-24 00:10:52 -0600 )edit

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

FreeApe gravatar imageFreeApe ( 2015-12-24 00:54:01 -0600 )edit

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

FreeApe gravatar imageFreeApe ( 2015-12-24 00:55:10 -0600 )edit

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

berak gravatar imageberak ( 2015-12-24 01:07:45 -0600 )edit

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

FreeApe gravatar imageFreeApe ( 2015-12-24 01:39:52 -0600 )edit

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

[24 4]

berak gravatar imageberak ( 2015-12-24 01:57:49 -0600 )edit

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

FreeApe gravatar imageFreeApe ( 2015-12-24 04:45:16 -0600 )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 ( 2015-12-25 07:16:32 -0600 )edit