I am trying to code ""Cumulative Volume Delta" in AFL. My code is as follows -
_SECTION_BEGIN("Cumulative Volume Delta");
uw= IIf(C>O, H-C, H-O);
lw= IIf(C>O, O-L, C-L);
spread= (H-L);
bl= (spread - (uw-lw));
puw= (uw/spread);
plw= (lw/spread);
pbl= (bl/spread);
x= (pbl+(puw+plw)/2*Volume);
y= ((puw+plw)/2*Volume);
bv= IIf(C>O, x, y);
sv= IIf(C<O, x, y);
cl= Param("Cumulative Length", 14, 10, 100);
cbv= EMA(bv, cl);
csv= EMA(sv, cl);
cvd= (cbv-csv);
cvd_color= IIf(cvd>0, colorGreen, colorRed);
Plot(cvd, "Cumulative Volme Delta", cvd_color, styleHistogram | styleThick, width=3);
_SECTION_END();
It is not giving the desired result. Can anyone here please fix this? Thanks for your time. Regards.
Related
Edit: The exit of the maze is only found when there is an empty spot without any walls along the borders of the maze.
Edit2: I've changed the code a bit after receiving the help, but still encountered the same issue.
Could be that I did not use what was mentioned properly.
I've changed the snippet of my code to just one recursion (the moving up portion) to minimize unnecessary repetition when viewing the snippet.
(Still kind of new to coding, so hope you don't mind)
I am attempting to code for a program that prints the movement of a person finding a path through a given maze.
However, I've encountered a problem where after reaching the exit of the maze, the person walks back to the original position where he is at.
The original position is given by an (x, y) coordinate.
Here's a snippet of my function which finds the path through the maze:
bool find_path(char **maze, long **track, long rows, long cols, long x, long y, long steps)
{
bool found;
if (goal_found(maze, rows, cols, x, y)) {
return true;
}
track[y][x] = 2;
if (maze[y - 1][x] == EMPTY && track[y - 1][x] == 1) { // Move Up
steps++;
found = find_path(maze, track, rows, cols, x, y - 1, steps);
if (found) {
return true;
}
++steps;
}
}
Your program finds all paths through the maze; if you want to stop it, you need to change your invocations to stop traversing the maze if you hit success:
found = search_maze(maze, track, rows, cols, x, y + 1, steps);
swap(maze, y, x, y + 1, x);
if (found) {
return found;
}
At all of the recursive invocations.
I am doing a program to display a three dimensional cube on the screen. I am doing the program in DOSBOX. My algorithm is as follows:
1. I take the length of the side as input from the user
2.I draw the cube with the initial coordinate prefixed as (140,280,0)
3. I convert the 3-D representation to 2-D by using the formula x=x+(z/sqrt(6))
The following is my code:
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
float idmat[4][4],inpmat[4][8];
void main()
{
int gd=DETECT,gm;
float s,temz,sqp,tx1,ty1,tz1;
int i,tz,j,side,d2mat[3][8],tx,ty;
for(i=1;i<=4;i++)
{for(j=1;j<=4;j++)
idmat[i][j]=0;
}
for(i=0;i<4;i++)
{for(j=0;j<4;j++)
{if(i==j)
{
idmat[i][j]=1;
}
}}
printf("Enter the side of the cube\n");
scanf("%d",&side);
inpmat[1][1]=140;
inpmat[2][1]=280;
inpmat[3][1]=0;
tx=140;
ty=280;
tz=0;
tx=tx+side;
inpmat[1][2]=tx;
inpmat[2][2]=ty;
inpmat[3][2]=tz;
ty=ty+side;
inpmat[1][3]=tx;
inpmat[2][3]=ty;
inpmat[3][3]=0;
tx=inpmat[1][1];
inpmat[1][4]=tx;
inpmat[2][4]=ty;
inpmat[3][4]=tz;
tz=tz+side;
printf("tz is %d ",tz);
inpmat[1][5]=tx;
inpmat[2][5]=ty;
inpmat[3][5]=tz;
tx=tx+side;
inpmat[1][6]=tx;
inpmat[2][6]=ty;
inpmat[3][6]=tz;
ty=ty+side;
inpmat[1][7]=tx;
inpmat[2][7]=ty;
inpmat[3][7]=tz;
tx=inpmat[1][1];
inpmat[1][8]=tx;
inpmat[2][8]=ty;
inpmat[3][8]=tz;
for(i=1;i<=8;i++)
inpmat[4][i]=1;
sqp=sqrt(6);
printf("The sqrt is %f \n",sqp);
for(i=1;i<=8;i++)
{
tx1=inpmat[1][i];
printf("%f ",inpmat[1][i]);
ty1=inpmat[2][i];
printf("%f lala\n ",inpmat[3][i]);
tz1=inpmat[3][i];
printf("prr %f \n",tz1);
temz=tz1/sqrt(6);
printf("temz is %f \n",temz);
tx1=tx1+temz;
ty1=ty1+temz;
d2mat[1][i]=tx1;
// printf("%f ",d2mat[1][i]);
d2mat[2][i]=ty1;
// printf("%f ",d2mat[2][i]);
d2mat[3][i]=1;
// printf("%f \n",d2mat[3][i]);
}
initgraph(&gd,&gm,"C:\\TurboC3\\BGI\\");
line(d2mat[1][1],d2mat[2][1],d2mat[1][2],d2mat[2][2]);
line(d2mat[1][2],d2mat[2][2],d2mat[1][3],d2mat[2][3]);
line(d2mat[1][3],d2mat[2][3],d2mat[1][4],d2mat[2][4]);
line(d2mat[1][4],d2mat[2][4],d2mat[1][1],d2mat[2][1]);
//printf("%f %f %f %f ",inpmat[1][4],inpmat[2][4],inpmat[1][6],inpmat[2][6]);
line(d2mat[1][5],d2mat[2][5],d2mat[1][6],d2mat[2][6]);
line(d2mat[1][6],d2mat[2][6],d2mat[1][7],d2mat[2][7]);
line(d2mat[1][7],d2mat[2][7],d2mat[1][8],d2mat[2][8]);
line(d2mat[1][8],d2mat[2][8],d2mat[1][5],d2mat[2][5]);
line(d2mat[1][5],d2mat[2][5],d2mat[1][1],d2mat[2][1]);
line(d2mat[1][6],d2mat[2][6],d2mat[1][2],d2mat[2][2]);
line(d2mat[1][8],d2mat[2][8],d2mat[1][4],d2mat[2][4]);
line(d2mat[1][7],d2mat[2][7],d2mat[1][3],d2mat[2][3]);
getch();
//closegraph();
//restorecrtmode();
}
When the figure is drawn on the screen, what i get is a cuboid instead of a perfect cube. Can somebody help me with this situation? Thanks in advance.
Thanks to all those looked into my question.I found the mistake in my program.
Before I enter inpmat[1][7],inpmat[2][7],inpmat[3][7], I was supposed to do ty=ty-side so that the y coordinate moves back to the initial position. Instead I did ty=ty+side and when drew the figure. When I saw that the resultant figure was wrong, I tried editing the code for drawing the lines accordingly instead of looking into the above section of the code. I am sorry for waiting your valuable time.
Hi I am trying to stitch some images without using the stitch class provided by opencv. But, the output is quit unexpected.
I will explain it with the input and output image.
input1
input2
expected output
real output
I think something is wrong with my ROI copying. anybody please help !!!
My code for stitching part is as follows-
std::vector< Point2f > points1,points2;
for( int i = 0; i < matches1.size(); i++ )
{
points1.push_back( keypoints_input1[matches1[i].queryIdx ].pt );
points2.push_back( keypoints_input2[matches1[i].trainIdx ].pt );
}
/* Find the Homography Matrix for current and next frame*/
Mat H1 = findHomography( points2, points1, CV_RANSAC );
/* Use the Homography Matrix to warp the images*/
cv::Mat result1;
warpPerspective(input2, result1, H1, Size(input2.cols+150, input2.rows+150), INTER_CUBIC);
Mat stitch_1(Size(input2.cols+150, input2.rows+150),CV_8UC3);
Mat roi1(stitch_1, Rect(0, 0, input1.cols, input1.rows));
Mat roi2(stitch_1, Rect(0, 0, result1.cols, result1.rows));
input2.copyTo(roi1);
result1.copyTo(roi2);
Can anybody tell me where I am going wrong ? thanks.
Edit: input1(640,360) and input2(790,510) are of different size.
I hope that this example helps you.
It's interesting to test on different images.
EDIT:
try this code:
Mat stitch_1(Size(input2.cols*2+ input1.rows,input2.rows*2),CV_8UC3);
Mat roi1(stitch_1, Rect(0, 0, input1.cols, input1.rows));
Mat roi2(stitch_1, Rect(0, 0, result1.cols, result1.rows));
result1.copyTo(roi2);
input1.copyTo(roi1);
imshow("final", stitch_1);
I use the following call to openCV function to perform K-means algorithm:
cvKMeans2(points, count, &clusters, cvTermCriteria( CV_TERMCRIT_EPS+CV_TERMCRIT_ITER, 10, 1.0 ), 1, CV_KMEANS_USE_INITIAL_LABELS, centers);
where
image2 = cvLoadImage( "lab.jpg", 0);
points = cvCreateMat( image2->height, image2->width, CV_32FC1 );
cvConvert(image2, points);
//count= number of clusters.
CvMat* centers; // To store the center of each cluster. (output).
lab.jpg is an image in CIE L*a*b* format.
But the above line, while compiling, shows the following errors:
`CV_KMEANS_USE_INITIAL_LABELS' undeclared (first use in this function)
too many arguments to function `cvKMeans2'
It would be very helpful if someone can point out where am wrong, specially the first error which says KMEANS_USE_INITIAL_LABELS undeclared.
Thanks in advance !
From the opencv doc for cvKMeans2:
flags – Can be 0 or CV_KMEANS_USE_INITIAL_LABELS.
You left out CV_.
Edit: also note that there should be two arguments between termcrit and flags, so you are skipping either attempts or rng. Try
cvKMeans2(points, count, &clusters, cvTermCriteria( CV_TERMCRIT_EPS+CV_TERMCRIT_ITER, 10, 1.0 ), 1, 0, CV_KMEANS_USE_INITIAL_LABELS, centers);
I hope that you can help me...
I have an IplImage (reimg_right) 320 X 240, IPL_DEPTH_32F
and I want to save it as an image and as an xml file.
I use this code:
sprintf(name1,"path1/image.bmp");
sprintf(name2,"path2/feature_image32F.xml");
cvSaveImage(name1,reimg_right);
cvSave(name2, reimg_right, NULL, NULL, cvAttrList(0,0));
all is ok but the problem is that in the xml file I don't have a matrix 320 X 240 but a matrix 19200 X 4 !!!
someone knows how to hold the dimensions?
thanks gabriele
I don't know what OpenCV version you are using, but some time ago you could do just:
cvSave("file.xml", my_img);
assuming my_img as:
CvMat* my_img = cvCreateMat(320, 240, CV_32FC1);
But since you are using an IplImage, you could convert them like:
CvMat mat;
CvMat* my_img = cvGetMat(reimg_right, &mat);
cvSave("file.xml", my_img);