最近学习OpencvSharp使用Opencv仿照C++opencv翻译过来。举个例子,图像融合C++版

  

clock_t start1, end1;
     clock_t start2, end2;    Mat src = imread("D:/dd.jpg");
     Mat dst = imread("D:/ss.jpg ");    Mat src_mask = 255 * Mat::ones(src.rows, src.cols, src.depth());
     Point center(dst.cols / 2, dst.rows / 2);    Mat normal_clone;
     Mat mixed_clone;    start1 = clock();
     seamlessClone(src, dst, src_mask, center, normal_clone, NORMAL_CLONE);
     end1 = clock();    start2 = clock();
     seamlessClone(src, dst, src_mask, center, mixed_clone, MIXED_CLONE);
     end2 = clock();    printf("NORMAL_CLONE use time: %d\n", end1 - start1);
     printf("MIXED_CLONE use time: %d\n", end2 - start2);    imshow("ROI_img", src);
     imshow("bg_img", dst);
     imshow("normal_clone", normal_clone);
     imshow("mixed_clone", mixed_clone);
     waitKey(0);


上面MFC上面跑起来没问题,翻译成C#版

Mat src =Cv2.ImRead("D:/dd.jpg");
     Mat dst = Cv2.ImRead("D:/ss.jpg ");    Mat src_mask = 255 * Mat.Ones(src.Size(),MatType.CV_8U);
     OpenCvSharp.Point center=new OpenCvSharp.Point(dst.Cols / 2, dst.Rows / 2);    Mat normal_clone=new Mat();
     Mat mixed_clone=new Mat();
         Cv2.SeamlessClone(src, dst, src_mask, center, normal_clone, SeamlessCloneMethods.NormalClone);
         Cv2.SeamlessClone(src, dst, src_mask, center, mixed_clone, SeamlessCloneMethods.MixedClone); Cv2.ImShow("ROI_img", src);
  Cv2.ImShow("bg_img", dst);
  Cv2.ImShow("normal_clone", normal_clone);
  Cv2.ImShow("mixed_clone", mixed_clone);
  Cv2.WaitKey(0);