OpenCV为不同的操作系统和不同的移动设备提供不同的结果

时间:2017-03-22 05:59:57

标签: android opencv android-ndk

我使用OpenCV C ++对图像进行了一些操作。在桌面上,我的结果越来越好但是当我将相同的本机代码移植到Android时,它会给出不同的结果,这对我来说毫无用处。

此外,结果因移动设备而异,即在一个移动设备中,我得到的结果与其他移动设备不同。

我的代码如下:

//适用于Android

int processingHologram(Mat img,Mat& output)
{
    Mat gray,dst,gaussianBlur,imageEmboss;
    Mat kernel,kernelEmboss;
    Point anchor;
    double delta;
    int ddepth;
    cvtColor(img,gray,CV_RGBA2GRAY);
    gray=imageCropNew(gray);

    // Initialize arguments for the filter
    anchor = Point( -1, -1);
    delta = 0;
    ddepth = -1;
    kernel= (Mat_<float>(5,5) <<
             1, 1, 1, 1,  1,
            -1, 1, 1,  1,  1,
            -1, -1,  1,  1,  1,
            -1,  -1,  -1,  -1,  1,
            -1,  -1,  -1,  -1,  -1 );

    filter2D(gray, dst, ddepth , kernel, anchor, delta, BORDER_DEFAULT );
    //dst=dst/2;
    //gaussianBlur= dst.clone();

    dst=dst+56;
    filter2D(dst, dst, ddepth , kernel, anchor, delta, BORDER_DEFAULT);
    GaussianBlur(dst, gaussianBlur, cv::Size(3, 3),0);
    addWeighted(dst, 4.5, gaussianBlur, -3.5, 5, gaussianBlur);
    gaussianBlur=gaussianBlur+56;
    Mat element = getStructuringElement( MORPH_DILATE,Size(3,3), Point(0,0) );
    //morphologyEx(gaussianBlur, gaussianBlur, MORPH_TOPHAT, element, Point(-1,-1), 1, BORDER_CONSTANT,morphologyDefaultBorderValue());
    dilate(gaussianBlur, gaussianBlur, element );
    kernelEmboss=(Mat_<float>(3,3) <<
                      -1,  0, 1,
                      -1,  0, 1,
                      -1,  0, 1);

    imageEmboss=Mat(dst.rows,dst.cols,CV_32SC1, Scalar(0));
    filter2D(gaussianBlur, imageEmboss, ddepth , kernelEmboss, anchor, delta, BORDER_ISOLATED);
    imageEmboss.convertTo(output, CV_32SC1);
    //dst.convertTo(output, CV_8UC1);

    return 0;
}

// For Desktop

#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <stdlib.h>
#include <stdio.h>
#include "ImageCropNew.h"
#include <iostream>
#include "updateMag.h"
#include "computeDFT.h"
#include "computeIDFT.h"

using namespace cv;
using namespace std; 
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <stdlib.h>
#include <stdio.h>
#include "ImageCropNew.h"
#include <iostream>
#include "updateMag.h"
#include "computeDFT.h"
#include "computeIDFT.h"

using namespace cv;
using namespace std; 


/** @function main */
int main ( int argc, char** argv )
{
  /// Declare variables
  Mat src, dst, diagonal, imageEmboss;

  Mat kernel;
  Point anchor;
  double delta;
  int ddepth;
  int kernel_size=3;
  char* window_name = "filter2D Demo";

  int c;

  /// Load an image
  src = imread( argv[1],CV_LOAD_IMAGE_COLOR);
  cvtColor(src,src,CV_RGBA2GRAY);
  src = imageCropNew(src);


  imshow("Source Image", src );

  if( !src.data )
  { return -1; }

  /// Create window

  namedWindow(window_name,CV_LOAD_IMAGE_GRAYSCALE);  


  /// Initialize arguments for the filter
  anchor = Point( -1, -1);
  delta = 0;
  ddepth = -1;


  kernel= (Mat_<float>(5,5) <<
            1, 1, 1, 1,  1, 
            -1, 1, 1,  1,  1, 
            -1, -1,  1,  1,  1, 
            -1,  -1,  -1,  -1,  1, 
             -1,  -1,  -1,  -1,  -1 );

  // Apply filter
  filter2D(src, dst, ddepth , kernel, anchor, delta, BORDER_DEFAULT );    

  diagonal= dst.clone();

  dst=dst/20;
  dst=dst+56;
  filter2D(dst, dst, ddepth , kernel, anchor, delta, BORDER_DEFAULT);

  dst=dst/2;
  Mat image;
  cv::GaussianBlur(dst, image, cv::Size(3, 3),0);  

  cv::addWeighted(dst, 4.5, image, -3.5, 5, image);
  filter2D(dst, dst, ddepth , kernel, anchor, delta, BORDER_DEFAULT);

  image=image+56;



  Mat element = getStructuringElement( MORPH_DILATE,Size(2,2), Point(0,0) );


  dilate( image, image, element );
  imshow("Dilation",image);

  Mat kernelEmboss=(Mat_<float>(3,3) <<
            -1,  0, 1, 
            -1,  0, 1, 
            -1,  0, 1);


  filter2D(image, imageEmboss, ddepth , kernelEmboss, anchor, delta, BORDER_ISOLATED);
  imshow("Image Emboss",imageEmboss);
   Mat kernel45degree=(Mat_<float>(3,3) <<
            4,  -2, -2, 
            -2,  4, -2, 
            -2,  -2, 4);


  filter2D(imageEmboss, diagonal, ddepth , kernel45degree, anchor, delta, BORDER_ISOLATED);
  Mat finalResult=image-diagonal;

  char name [50];

  imshow("Diagonal",diagonal);

  imshow("Final Result",dst);

  sprintf(name,"diagonal.jpg");
  imwrite(name,diagonal);    
  waitKey(0); 
  return 0;
}

在桌面设备中,与移动设备相比,结果的可见性更高。

任何人都可以了解如何在不同的移动型号上获得一致的结果,并且在桌面上获得相同的结果吗?

0 个答案:

没有答案