imread是学OpenCV 的第一个函数了,一直都用默认的方式也就是cv::imread("图像名");
但是在执行一个简单的图像锐化算法的时候输出图像总是输入图像的1/3,请教师兄后才知道是图像读入的问题。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
#include
#include
#include
using
namespace
std
;
using
namespace
cv
;
void
sharpen
(
const
Mat
&
image
,
Mat
&
result
)
{
result
.
create
(
image
.
size
(),
image
.
type
());
for
(
int
j
=
1
;
j
<
image
.
rows
-
1
;
j
++
)
{
const
uchar
*
previous
=
image
.
ptr
<
const
uchar
>
(
j
-
1
);
const
uchar
*
current
=
image
.
ptr
<
const
uchar
>
(
j
);
const
uchar
*
next
=
image
.
ptr
<
const
uchar
>
(
j
+
1
);
uchar
*
output
=
result
.
ptr
<
uchar
>
(
j
);
for
(
int
i
=
1
;
i
<
image
.
cols
-
1
;
i
++
)
{
*
output
++
=
saturate_cast
<
uchar
>
(
5
*
current
[
i
]
-
current
[
i
-
1
]
-
current
[
i
+
1
]
-
previous
[
i
]
-
next
[
i
]);
}
}
result
.
row
(
0
).
setTo
(
Scalar
(
0
));
result
.
row
(
result
.
rows
-
1
).
setTo
(
Scalar
(
0
));
result
.
col
(
0
).
setTo
(
Scalar
(
0
));
result
.
col
(
result
.
cols
-
1
).
setTo
(
Scalar
(
0
));
}
int
main
()
{
clock_t
start_time
=
clock
();
Mat
image
=
imread
(
"home.tif"
,
CV_LOAD_IMAGE_UNCHANGED
);
if
(
!
image
.
data
)
{
cout
<<
"Cannot Open!!"
<<
endl
;
}
imshow
(
"Original"
,
image
);
Mat
result
;
sharpen
(
image
,
result
);
imshow
(
"result"
,
result
);
waitKey
(
0
);
clock_t
end_time
=
clock
();
cout
<<
"Running Time: "
<<
static_cast
<
double
>
(
end_time
-
start_time
)
/
CLOCKS_PER_SEC
<<
"s"
<<
endl
;
system
(
"PAUSE"
);
return
0
;
}
|
在reference里imread的各个参数如下:
C++: Mat imread(const string& filename, int flags=1 )
|