PDA

View Full Version : How to display image transformed into integral image on label?(OpenCV)



jcheng
18th October 2015, 10:12
Hi, I would like to put the output in the white area, this is my GUI11452,and this output11453
This is my code:


#include "haar.h"
#include "ui_haar.h"
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
using namespace std;
using namespace cv;
HAAR::HAAR(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::HAAR)
{
ui->setupUi(this);
}

HAAR::~HAAR()
{
delete ui;
}

void HAAR::on_pushButton_clicked()
{
Mat frame;
//VideoCapture cap(0);
//while(true){
//cap>>frame;

frame=cv::imread("C:\\Users\\OpenCL\\Documents\\QT Pro\\H\\1.jpg");//read image.
//double t = (double)getTickCount();
float A[30][30];
//float **A = (float**)malloc(sizeof(float)*(frame.cols+1)*(fram e.rows+1));
//for(int k=0;k<frame.cols+1;k++) A[k]=(float*)malloc(sizeof(float)*(frame.rows+1));
for(int i=0;i<frame.cols+1;i++) for(int j=0;j<frame.rows+1;j++)A[i][j]=0;
for(int y=0;y<frame.rows;y++){
float sum=0;
uchar* ptr1=frame.ptr<uchar>(y);
for (int x=0; x<frame.cols; x++) {
sum=sum+(float)((ptr1[3*x]+ptr1[3*x+1]+ptr1[3*x+2])/3);

A[x+1][y+1] = A[x+1][y] + sum;

}
cout<<endl;
}

cout<<"Integration Picture:"<<endl<<endl;
for(int j=0;j<frame.rows+1;j++,cout<<endl)
for(int i=0 ;i<frame.cols+1;i++)
{
cout<<A[i][j]<<" ";


cout<<endl;
}

anda_skoa
18th October 2015, 12:06
You want the A values to be displayed in the window instead of written to stdout?

If so just build a QString with concatenation, using QString::number() to format the floats into strings.

Or use a QTextStream on a QString pointer and stream similar to what you have now, then take the resulting QString.

Cheers,
_