How to read image using opencv C++ using Google Colab and store values in MAT. Mat gives error

603 Views Asked by At

I am trying to read an image and store it values in Mat and further use those values in google Colab using openccv C++. but i am unable to use the functions properly as i am attaching the code and google colab is unable to run it.

#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

The problem looks in meanStdDev(image, mean, stddev, cv::Mat::Mat()); and

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

Thank you

0

There are 0 best solutions below