博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Software Testing:简要描述领你印象最深的error在你的项目
阅读量:5115 次
发布时间:2019-06-13

本文共 2629 字,大约阅读时间需要 8 分钟。

 

problem:

In a program that uses Opencv for image processing. My goal is to use the camera to identify the precise coordinates of multiple balls. But because of the light, in the identification process, the coordinates of the ball sometimes accurate sometimes sometimes inaccurate, in order to make each identified the ball coordinates can be more accurate. We need to each ball to identify the coordinates of the average to get a more accurate coordinates.

I use the following way to average the ball coordinates.

First, we should save the coordinates identified this time to the array ballpre [], and then to the next time to identify the ball in the process, with the coordinates (x, y) and ballpre [] coordinates in the calculation of the distance. The minimum distance is to identify the coordinates of a same small ball, and then add them together. Finally using the sum of coordinates divided by the number of times identified by the coordinates.

At first I thought that my method was right, but at the time of the run, I found that the result was wrong.

Why this error impress I most?

Because this problem I spent a lot of time, at first thought that the algorithm error, and constantly to check the algorithm and grammar. There is another reason that this project is submitted in my first time to participate in the competition.

How did I find it?    What is the error?

And then I print out the data every time, analyze it, I found that the reason is that some of the ball in a recognition process has not been identified, so it is divided by the number of identification should not be the total number of identification.

 

Solution:Add an array to control the number of times the ball is recognized. We use the elements in this array as the denominator of the above formula.

The following is the specific code:

 

for (int i = 0; i < MIN(count_x, 20); i++)

        {

            if (ci == 0)

            {

                xx1[i] = x[i];

                yy1[i] = y[i];

                sum_x[i] += x[i];

                sum_y[i] += y[i];

                for (int i = 0; i < count_x; i++)

                {

                    sumx[i] = 1;

                }

                for (int i = count_x; i < 100; i++)

                {

                    sumx[i] = 0;

                }

            }

            for (int j = 0; j < count_x; j++)

            {

                //float * q = (float *)cvGetSeqElem(cir, j);

                if (ci > 0)

                {

                    double a = pow(x[j] - xx1[i], 2) + pow(y[j] - yy1[i], 2);

                    if (cvRound(sqrt(a)) <= 15)

                    {

                        //cout << cvRound(q[0]) << "   " << x1[i] << endl;

                        //cout << cvRound(q[1]) << "   " << y1[i] << endl;

                        //cout << "sqrt(a)" << sqrt(a) << endl;

                        sum_x[i] += x[j];

                        sum_y[i] += y[j];

                        sumx[i]++;

                        break;

                    }

                    if (j == count_x&&cvRound(sqrt(a)) > 15)

                    {

                        sum_x[j] += x[j];

                        sum_y[j] += y[j];

                        sumx[j]++;

                    }

                }

 

            }

           

                        xx[i] = sum_x[i] / sumx[i];

                        yy[i] = sum_y[i] / sumx[i];

                       

 

                    }

 

               }

转载于:https://www.cnblogs.com/mjm212/p/6441795.html

你可能感兴趣的文章
sql server必知多种日期函数时间格式转换
查看>>
ListView如何获取点击单元格内容
查看>>
jQuery EasyUI 的下拉选择combobox后台动态赋值
查看>>
timeline时间轴进度“群英荟萃”
查看>>
python if else elif statement
查看>>
网络编程
查看>>
文本隐藏(图片代替文字)
查看>>
three.map.control
查看>>
java面试题
查看>>
提高码力专题(未完待续)
查看>>
IOS第17天(3,Quartz2D画板和画线)
查看>>
pair的例子
查看>>
前端框架性能对比
查看>>
@property中 retain 详解
查看>>
java8 stream初试,map排序,list去重,统计重复元素个数,获取map的key集合和value集合...
查看>>
Python爬虫个人记录(四)利用Python在豆瓣上写一篇日记
查看>>
uva 387 A Puzzling Problem (回溯)
查看>>
12.2日常
查看>>
12.3日常
查看>>
Delphi 取整函数round、trunc、ceil和floor
查看>>