opengl保存img,img.data每个点都是三维坐标,在用opencv的imread打开后,如何获取这些三维顶点

0dawn 2017-03-14 11:24:57
opengl保存img,img.data每个点都是三维坐标,在用opencv的imread打开后,如何获取这些三维顶点?急,在线等,谢谢
...全文
943 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
0dawn 2017-03-14
  • 打赏
  • 举报
回复
引用 7 楼 zhao4zhong1 的回复:
只听说过2D轮廓,没听说过3D轮廓。
如果不能获取的话,那绑定的顶点信息保存在哪里呢?是这样绑定的
glBufferData(GL_ARRAY_BUFFER, 3 * openGLBuffer.vcnt*sizeof(double), vertexs.data(), GL_STATIC_DRAW);
vertexs.data()里面是一系列顶点
0dawn 2017-03-14
  • 打赏
  • 举报
回复
引用 7 楼 zhao4zhong1 的回复:
只听说过2D轮廓,没听说过3D轮廓。
我也很疑惑啊 只是一张图片中检测轮廓,但是这个图片先前用opengl 的vbo绑定了三维的顶点信息(世界坐标信息,三角网),现在在opencv中cvGetSeqElem获取到的都是像素坐标,这个现在真不知道怎么获取,或者怎么转换
赵4老师 2017-03-14
  • 打赏
  • 举报
回复
只听说过2D轮廓,没听说过3D轮廓。
赵4老师 2017-03-14
  • 打赏
  • 举报
回复
仅供参考:
const static Scalar colors[15]={
    CV_RGB(  0,  0,128),
    CV_RGB(  0,128,  0),
    CV_RGB(  0,128,128),
    CV_RGB(128,  0,  0),
    CV_RGB(128,  0,128),
    CV_RGB(128,128,  0),
    CV_RGB(128,128,128),
    CV_RGB(160,160,160),
    CV_RGB(  0,  0,255),
    CV_RGB(  0,255,  0),
    CV_RGB(  0,255,255),
    CV_RGB(255,  0,  0),
    CV_RGB(255,  0,255),
    CV_RGB(255,255,  0),
    CV_RGB(255,255,255),
};
Scalar color;
vector<Vec4i> hierarchy;
vector<vector<Point> > contours;
Mat bw;
int idx,n;
Rect maxrect,brect;
Mat smallImg(600,600,CV_8UC1);

    cvNamedWindow("display",1);
        findContours(bw,contours,hierarchy,RETR_EXTERNAL,CHAIN_APPROX_SIMPLE);
        if (!contours.empty()&&!hierarchy.empty()) {
            idx=0;
            n=0;
            vector<Point> approx;
            for (;idx>=0;idx=hierarchy[idx][0]) {
                color=colors[idx%15];
                drawContours(smallImg,contours,idx,color,1,8,hierarchy);
                approxPolyDP(Mat(contours[idx]), approx, arcLength(Mat(contours[idx]), true)*0.005, true);//0.005为将毛边拉直的系数
                const Point* p = &approx[0];
                int m=(int)approx.size();
                polylines(smallImg, &p, &m, 1, true, color);
                circle(smallImg,Point(p[0].x,p[0].y),2,color);
                circle(smallImg,Point(p[1].x,p[1].y),1,color);

                n++;
                if (1==n) {
                    maxrect=boundingRect(Mat(contours[idx]));
                } else {
                    brect=boundingRect(Mat(contours[idx]));
                    CvRect mr(maxrect),br(brect);
                    maxrect=cvMaxRect(&mr,&br);
                }
            }
            circle(smallImg,Point(maxrect.x+maxrect.width/2,maxrect.y+maxrect.height/2),2,CV_RGB(255,0,0));
        }
        imshow("display",smallImg);
        waitKey(0);
    cvDestroyWindow("display");
0dawn 2017-03-14
  • 打赏
  • 举报
回复
引用 2 楼 zhao4zhong1 的回复:
假定每个点的三维坐标的类型为unsigned char;
Mat img = imread("filename.bmp");
    for( int y = 0; y < img.rows; y++ )
    {
        for( int x = 0; x < img.cols; x++ )
        {
            Vec3d a3dpoint = img.at<Vec3b>(y,x);
        }
    }

目前只知道cvGetSeqElem,但是好像得到的结果不对。。。
0dawn 2017-03-14
  • 打赏
  • 举报
回复
引用 2 楼 zhao4zhong1 的回复:
假定每个点的三维坐标的类型为unsigned char;
Mat img = imread("filename.bmp");
    for( int y = 0; y < img.rows; y++ )
    {
        for( int x = 0; x < img.cols; x++ )
        {
            Vec3d a3dpoint = img.at<Vec3b>(y,x);
        }
    }

老师果然牛逼呀! 现在我用这个图片进行轮廓查找,如下:
cv::Mat img = cv::imread(ImgfileName, 1);
	if (img.empty())
	{
		return;
	}
	cv::Mat contoursImg;
	cv::cvtColor(img, contoursImg, CV_BGR2GRAY);

	cv::threshold(contoursImg, contoursImg, 1, 255, CV_THRESH_BINARY);
	cv::Mat kernle = (cv::Mat_<uchar>(3, 3) << 1, 1, 1, 1, 1, 1, 1, 1, 1);
	cv::morphologyEx(contoursImg, contoursImg, CV_MOP_OPEN, kernle, cv::Point(-1, -1), 3);

	CvMemStorage* mem_storage = cvCreateMemStorage(0);
	CvSeq *first_contour = NULL, *c = NULL;

	cvFindContours(&contoursImg.operator IplImage(), mem_storage, &first_contour,sizeof(CvContour), CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE);
	std::vector<std::vector<cv::Point>> subcontours;
该如何得到每个contours的三维点坐标呀
0dawn 2017-03-14
  • 打赏
  • 举报
回复
引用 1 楼 worldy 的回复:
opencv能打开opengl的文档?
不是,是图片,只是opengl操作了顶点,然后保存了,现用opencv cv::imread打开图片,希望获得图片中每个顶点的三维坐标,不知道这样可不可以诶
赵4老师 2017-03-14
  • 打赏
  • 举报
回复
假定每个点的三维坐标的类型为unsigned char;
Mat img = imread("filename.bmp");
    for( int y = 0; y < img.rows; y++ )
    {
        for( int x = 0; x < img.cols; x++ )
        {
            Vec3d a3dpoint = img.at<Vec3b>(y,x);
        }
    }

worldy 2017-03-14
  • 打赏
  • 举报
回复
opencv能打开opengl的文档?

24,854

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧