2

I was coding the Python version of one of the C++ tutorials and noticed that the output image was different depending if I was using C++ or Python.

For example, with our friend Lena:

enter image description here

C++ code:

#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 code:

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++ image output:

enter image description here

Python image output:

enter image description here

Do you have any idea why this happens?

codeherk
  • 1,609
  • 15
  • 24
João Cartucho
  • 3,688
  • 32
  • 39

1 Answers1

2

Too late for answer, but it works if you specify argument name 'ksize' in python code:

dst = cv2.Laplacian(src, ddepth, ksize=kernel_size)
KOlegA
  • 638
  • 6
  • 8