In dart, create JPEG file is like:

import 'dart:io';
import 'package:image/image.dart';

...

List<int> resizedBytes = encodeJpg(resizedImage);
File(outputPath).writeAsBytesSync(resizedBytes)

In python, we usually use:

import cv2

...

cv2.imwrite("output.jpg", output_image)

But they are different! As the source code show, the “encodeJpg()” use 100% quality and YUV444 chroma as default, but cv2 use 95% quality and YUV420 chroma as default.

If you want to write a JPEG file just as “encodeJpg()” do by using python, the code snippet should be:

import cv2

...

params = [cv2.IMWRITE_JPEG_QUALITY, 100, cv2.IMWRITE_JPEG_SAMPLING_FACTOR, cv2.IMWRITE_JPEG_SAMPLING_FACTOR_444]
success, encoded_image = cv2.imencode(".jpg", output_image, params)
if success:
  with open(output_path, "wb") as fp:
    fp.write(encoded_image)