我正在编写其中一个C ++教程的Python版本,并注意到输出图像的不同取决于我使用的是C ++还是Python。
例如,与我们的朋友Lena:
C ++代码:
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui/highgui.hpp"
using namespace cv;
int main( int, char** argv )
{
Mat src, dst, abs_dst;
int kernel_size = 3;
int scale = 1;
int delta = 0;
int ddepth = CV_16S;
src = imread( argv[1] );
Laplacian( src, dst, ddepth, kernel_size, scale, delta, BORDER_DEFAULT );
convertScaleAbs( dst, abs_dst );
const char* window_name = "Laplace Demo";
namedWindow( window_name, WINDOW_AUTOSIZE );
imshow( window_name, abs_dst );
waitKey(0);
return 0;
}
Python代码:
import sys
import cv2
def main(argv):
ddepth = cv2.CV_16S
kernel_size = 3
src = cv2.imread(sys.argv[1], cv2.IMREAD_COLOR)
dst = cv2.Laplacian(src, ddepth, kernel_size)
abs_dst = cv2.convertScaleAbs(dst)
window_name = "Laplace Demo"
cv2.namedWindow(window_name, cv2.WINDOW_AUTOSIZE)
cv2.imshow(window_name, abs_dst)
cv2.waitKey(0)
return 0
if __name__ == "__main__":
main(sys.argv[1:])
C ++图像输出:
Python图像输出:
你知道为什么会这样吗?
答案 0 :(得分:1)
为时已晚,但是如果您在python代码中指定参数名称“ ksize”,则该方法有效:
Settings