I would like to take a part of an image to 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 to the user. For this I want to use only the imread
functions to open the image and the imshow
to show (nothing more than that of OpenCV) but I can not show the cropped image gives error in the imshow
line (does not accept this type of data). The code I'm 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 error you give is this:
error: no matching function for call to 'imshow(const char [2], int [600])'|
But I'd like to show the vector I got without needing to be using the OpenCV data types.
EDIT:
My goal is to take this part of the image and show it to the user. That in this case would be the content of matrix m. But I'm not able to use this together with imshow. I tried to do it this 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 did not work. It is all black which does not match the part of the image. Is there any more efficient way to declare the array "copy" to properly accept the integer? Or is there a more appropriate way to do this to be able to show the captured image?