Learn to indent properly your code, it show its structure and it helps reading and understanding.
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/core/mat.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include<iostream>
#include<math.h>
#include<time.h>
using namespace std;
using namespace cv;
int main(int argc, char *argv[])
{
system("clear");
Mat src=imread("/home/Adam/Bureau/2.jpg",0);
float mean,s,v,e;
int a=src.rows, b=src.cols;
time_t t;
srand((unsigned) time(&t));
for(int i=0;i<src.rows;i++){
for(int j=0;i<src.cols;j++){ s+=src.at<float>(i,j); mean=s/(a*b);
e+=(src.at<float>(i,j)-mean)*(src.at<float>(i,j)-mean);
v=e/(a*b);
}
}
cout<<"the mean ="<<mean<<endl;
cout<<"la variance est ="<<v<<endl;
return 0;
}
Professional programmer's editors have this feature and others ones such as parenthesis matching and syntax highlighting.
Notepad++ Home[
^]
ultraedit[
^]
you need to read about C++ division of integers
When you don't understand what you code is doing or its results, the answer is debuggern it allow you to see exactly what your code is doing and to inspect the variables is it execute.
There is a tool that allow you to see what your code is doing, its name is
debugger. It is also a great learning tool because it show you reality and you can see which expectation match reality.
When you don't understand what your code is doing or why it does what it does, the answer is
debugger.
Use the debugger to see what your code is doing. Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute.
Debugger - Wikipedia, the free encyclopedia[
^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[
^]
Basic Debugging with Visual Studio 2010 - YouTube[
^]
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to. When the code don't do what is expected, you are close to a bug.