C++ 如何获得准确的中心点?

C++ 如何获得准确的中心点?,c++,opencv,transform,geometry,hough-transform,C++,Opencv,Transform,Geometry,Hough Transform,如何使用OpenCV Hough圆变换获得精确的中心点?我需要更多精确的x,y坐标的小数位数 (我的意思是这样的) 我用matlab得到了这些中心坐标 x107,775526315904 y112,963480232638 x469,550463441518 y208,309866770404 x217,386414755458 y490,882895036058 这是我的密码: #include <opencv2/highgui/highgui.hpp> #inclu

如何使用OpenCV Hough圆变换获得精确的中心点?我需要更多精确的x,y坐标的小数位数

(我的意思是这样的) 我用matlab得到了这些中心坐标

x107,775526315904   y112,963480232638
x469,550463441518   y208,309866770404
x217,386414755458   y490,882895036058
这是我的密码:

#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/core/core.hpp>
#include <iostream>
#include <stdio.h>

using namespace cv;
using namespace std;


int main()
{
    Mat src, src_gray, src0;
    printf("Give the name of the picture\n");
    char ImageName[20];
    scanf("%s", &ImageName);
    /// Read the image 
    src = imread(ImageName, 1);
    if (!src.data)
    {
        printf("no image data\n");
        return main();
    }
    // src0 = src;
    // imshow("orignal", src0);
    /// Convert it to gray
    cvtColor(src, src_gray, CV_BGR2GRAY);
    GaussianBlur(src_gray, src_gray, Size(9, 9), 2, 2);
    vector<Vec3f> circles;
    /// Apply the Hough Transform to find the circles
    HoughCircles(src_gray, circles, CV_HOUGH_GRADIENT, 0.92, src_gray.rows / 10, 20, 10, 55, 60);
    for (size_t i = 0; i < circles.size(); i++)
    {
        Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));
        int radius = cvRound(circles[i][2]);
    //  printf("%d center x %d y %d\n", i, cvRound(circles[i][0]), cvRound(circles[i][1]));
    //  printf("rad: %d\n", cvRound(circles[i][2]));
        cout << i + 1 << " centerpoint " << " x: " << circles[i][0] << "   y: " << circles[i][1] << "rad: " << circles[i][2] << endl;
        // cout << i + 1 << " othermethod" << "x : " << center.x << endl;
        // circle center
        circle(src, center, 1, Scalar(0, 255, 0), -1, 8, 0);
        // circle outline
        circle(src, center, radius, Scalar(255, 0, 0), 1, 8, 0);
    }
    imshow("circlefinder", src);
    waitKey(1);
    system("PAUSE");
    cvDestroyWindow("orignal");
    cvDestroyWindow("circlefinder");
    printf("new picture ?(y/n)");
    char ans[1];
    scanf("%s", &ans);
    if (strcmp(ans, "y"))
    {
        return 0;
    }
    else if (strcmp(ans, "n"))
    {
        return main();
    }

}

丢失的不是你的数据。这只是你跳过一些数字的打印功能

请尝试std::setprecision:

std::cout << 432.123456789f << "   " << std::setprecision(10) << 432.123456789f << std::endl;

std::请不要再定义“准确”了!您似乎正在执行
int/int
除法,这将导致一个(必须截断的)整数。尝试在除法之前将参数强制转换为
float
double
(无论库使用什么)。我看不出我在哪里进行int/int除法。我只打印来自hough变换的圆向量hough结果不够好?使用更高分辨率的图像!我需要它在实验室做一个实验,事实上,当我使用houghcircles时,它会从显微镜摄像头中获取图像。虽然它的高清(1080p)相机,我只使用了300x300的部分图像,实际上正如我写的,我只需要小数点后的3-4个数字,但你的方法并不能解决问题。我尝试了精度10,但只有弧度在小数点后有10个数字,并且x y坐标是相同的。。。。如果你看一下我的输出,它们总是以5结尾,你有没有找到提高OpenCV Hough圆变换精度的方法?为什么值总是nnn.5?
std::cout << 432.123456789f << "   " << std::setprecision(10) << 432.123456789f << std::endl;
#include <iomanip>