Error - create an image - different resolutions
Hello,
im trying to create a pricture from an array. Sometimes it works and sometimes not.
1st correct one: 500x503
2nd something wrong 500x500 (500x501, 500x502 the same) there is a diagonal in the picture and i dont know why.
1st:
2nd:
in the daten[count_array] are 500x500 values that need to be printed.
I dont want to paste the whole code, so here is just the interesting part:
.....
difference = max_value - min_value; //diff for scaling
skalierung = difference/255; //scaling
count_array = 0;
fp = fopen(dateiname,"w");//open file and write ...
if(fp==NULL)
fprintf(stderr,"Error!\n");
//write details in .txt
fprintf(fp,"%d\n",hoehe);//hight
fprintf(fp,"%d\n",breite);//width
fprintf(fp,"%Lf\n",min_value);
fprintf(fp,"%Lf\n",max_value);
//create picture
for(i=1; i<=((hoehe)*(breite)); i++) //height*width
{
lambda = daten[count_array]; //read Lyapunov-value from array
fprintf(fp,"%Lf\n",lambda); //write current value in .txt
count_array++; //next lyapunov value
for (n=min_value; n<=max_value; n=n+skalierung) //grey value 1-255
{
if (lambda>=n && lambda<(n+skalierung)) //correct grey value ?
{
//write pixel -> x start=0 ; y start=255 ; count= grey-value startvalue = 255
cvLine(img,cvPoint(x,y),cvPoint(x,y),CV_RGB(count,count,count));
Anzahl[count]=Anzahl[count]+1; //count number of pixels with that grey-value
break; //exit loop, go to next pixel
}
else
{
count=count-1; //no->next grey value
}
}
y=y-1;//decrease y -> rows
count=255;//grey-value -> start-value
//if y=0 increase x and set y to start-value
if (y==0)
{
y=hoehe;
x++;
}
}
for (i=0; i<=255; i++)
{
printf("Anzahl[%d]: %d\n", i, Anzahl[i]);//Number of pixels with grey-value i
}
//save,show,close picture
fclose(fp);
cvSaveImage(bildname, img);
cvNamedWindow("Test",2);
cvShowImage("Test",img);
cvWaitKey();
cvReleaseImage(&img);
cvDestroyWindow("Test");
}
Rule 1: if it is using IplImages, - it is outdated.
please lookup how to use cv::Mat instead
"I dont want to paste the whole code, so here is just the interesting part" - unfortunately, the only interesting part went missing, - how do you feed your data into opencv structures ?
The problem is, im not the best in programming. At the beginning, the includes (i use opencv 2.4.9 ) include <stdio.h> include <math.h> include <opencv2/opencv.hpp> include <opencv2/highgui/highgui.hpp> include <opencv/cv.h> include <math.h> include <stdlib.h> include <string.h>
include "Funktionen.h"
include <iostream>
define PI 3.14159265359
void SI_Function (char AB[75],int Voriteration, int Iteration, long double start, long double stoer, int hoehe, int breite, int laenge, long double x_achse_anfang, long double x_achse_ende, long double y_achse_anfang, long double y_achse_ende, long double b, char dateiname[75], char bildname[75]) { printf("SI-Function");
again, forget IplImages, cv* functions. it's all dead since 2010.