How to show image in Opencv?

Asked

Viewed 641 times

0

I would like to take a part of an image play it in an array pass some kind of filter on it manually( without using the Opencv functions) and show the result in a window for the user. For that I want to use only the functions imread to open the image and the imshow to show ( nothing more than that of Opencv) but I am not able to show the image cut gives error in the line of imshow( does not accept this type of data). The code I am using follows: :

#include <iostream>
#include <string>
#include <opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
using namespace std;
using namespace cv;

int main()
{


     Mat image = imread("Imagem5.png");
     int m[20][30];
     int v[600];

    // Pegando parte da imagem
     for(int i=0; i< 20 ;i++)
    {
        for(int j=0; j<30 ; j++)
        {
          m[i][j]=  (int)image.at<uchar>(i+20,j+30);
        }

    }
    // Mostrando no console 
     for(int i=0; i< 20 ;i++)
    {
        for(int j=0; j<30 ; j++)
        {
          cout <<  m[i][j] << " ";
        }
        cout << endl;
    }


      int indice =0;

         for(int i=0; i< 20 ;i++)
         {
            for(int j=0; j<30 ; j++)
            {
            // transformando em um vetor
                v[indice]=m[i][j];
                indice = indice +1;
            }

         }
         // mostrar o resultado obtido
    imshow("s",v); // da erro aqui
    waitKey();
    return 0;
}

The mistake is this :

error: no matching function for call to 'imshow(const char [2], int [600])'|

But I’d like to show you the vector I got without using Opencv data types.

EDITED :

My goal is to take this part of the image and show it to the user. Which in this case would be the content of the m matrix. But I’m not getting to use it along with imshow. I tried to do it that way :

Mat copia(242,208, CV_32F);

 for(int i=0; i< 242 ;i++)
    {
        for(int j=0; j<208 ; j++)
        {
        copia.at<int>(i,j)= m[i][j];
        }

    }


imshow("saída",copia);
waitKey();

But it didn’t work. Everything turns black, which doesn’t match the image part. Is there any more efficient way to declare the matrix "copy" to properly accept the integer ? Or is there some more appropriate way to do this convesion to show the captured image ?

1 answer

1


Response to editing:

Rect roi = Rect(0,0,208,242);
Mat copia = image(roi).clone();
imshow("teste", copia);

this is the most efficient way to solve your problem

  • Yes. My main goal is to show this part of the original matrix that was captured. What is not working is just to show it with imshow. PS: the question has been edited.

  • ready, edited the answer, this code solves the problem

Browser other questions tagged

You are not signed in. Login or sign up in order to post.