I am trying to 1)read an image into a matrix 2) Push the values of it inside a vector 3) Read those values back into a Matrix 4) Display it as an image
For this, the code i have coded goes as follows:
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <stdlib.h>
#include <stdio.h>
#include<iostream>
#include<conio.h>
using namespace std;
using namespace cv;
/** @function main */
int main( int argc, char** argv )
{
Mat src;
src = imread("s.png",1);
imshow("src",src);
std::vector<unsigned int> a;
std::vector<unsigned int> m;
int x1,x2,y1,y2,i,j;
unsigned int a1=0,c1=0;
Mat avg=Mat::zeros(src.rows,src.cols,CV_8UC3);
Mat avg1=Mat::zeros(100,100,CV_8UC1);
Mat coef=Mat::zeros(http://ift.tt/1wXXdLq);
for(int i=0;i<src.cols;i++)
{
for(int j=0;j<src.rows;j++)
{
int x;
x=(int)src.at<uchar>(j,i);
m.push_back(x);
}
}
Mat d=Mat::zeros(src.rows,src.cols,CV_8UC3);
int g=0;
for(int i=0;i<src.cols;i++)
{
for(int j=0;j<src.rows;j++)
{
int l=m.at(g++);
d.at<uchar>(j,i)=(uchar)l;
}
}
imshow("avg",d);
waitKey(0);
getch();
return 0;
}
On debugging, only half of the input image is getting displayed. Rest half of the image is getting displayed as black.
Kindly let me know where I am going wrong.
Thank you in advance
Aucun commentaire:
Enregistrer un commentaire