如何使用Opencv C ++和Google Colab读取图像并将值存储在MAT中。垫子出错

时间:2019-12-30 18:32:01

标签: c++ opencv google-colaboratory mat opencv-mat

我正在尝试读取图像并将其值存储在Mat中,并使用openccv C ++在google colab中进一步使用这些值。但是我无法正确使用这些功能,因为我正在附加代码,而Google colab无法运行它。

#include <vector>
#include <stdio.h>
#include "fstream"
#include "iostream"
#include <algorithm>
#include <iterator>
#include <cmath>
#include<stdlib.h>              
#include <math.h>


#include "opencv2/imgproc.hpp"
#include "opencv2/imgcodecs.hpp"

#include <iostream>
#include "opencv2/highgui.hpp"
#include <opencv2/core/utility.hpp>

using namespace std;
using namespace cv;
enter code here
cv::Scalar Kurtosis(cv::Mat image)
{
    cv::Scalar kurt, mean, stddev;
    kurt.val[0] = 0;

     meanStdDev(image, mean, stddev, cv::Mat::Mat());

    int sum0;
    int N = image.rows*image.cols;
    float den0  = 0;

    for (int i = 0; i < image.rows; i++)
    {
        for (int j = 0; j < image.cols; j++)
        {
            sum0 = image.ptr<uchar>(i)[3 * j] - mean.val[0];

            kurt.val[0] += sum0 * sum0*sum0*sum0;

            den0 += sum0 * sum0;
        }
    }

    kurt.val[0] = (kurt.val[0] * N*(N + 1)*(N - 1) / (den0*den0*(N - 2)*(N - 3))) - (3 * (N - 1)*(N - 1) / ((N - 2)*(N - 3)));


    return kurt;

}

int main(int argc, char** argv)
{

    #pragma region Initializeing Image

    Mat img;

  img =imread("5.png");
   try
   {   
        // cvwaitKey(1);
   }
   catch( const cv::Exception& e )
   {
         cerr << "exception caught: " << e.what() << endl;
   }

    cout<<"hello"<<endl;
    return 0;
}

Any help would be appreciated

问题出现在meanStdDev(image, mean, stddev, cv::Mat::Mat());

Mat img;
img =imread("5.png");

谢谢

0 个答案:

没有答案