opencv3学习之Point类

//13.Point

#include <opencv2/opencv.hpp>

using namespace cv;

using namespace std;

int main(){

    Point2f p1(6,2);//二维点的定义和输出

    cout<<"p1="<<p1<<endl;

    

    Point3f p2(1,2,3);//三维点的定义和输出

    cout<<"p2="<<p2<<endl;

    

    vector<float> v;

    v.push_back(4);

    v.push_back(5);

    v.push_back(6);

    cout<<"vector="<<Mat(v);//因为vector是基于Mat

    cout<<endl;

    

    

    vector<Point2f> points(20);

    for(size_t i=0;i<points.size();++i)

        points[i]=Point2f(float(i*5),float(i%7));

    

        cout<<points<<";";

    

    return 0;

}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
C++ Opencv是一个开源计算机视觉库,它包含了很多计算机视觉和机器学习的经典算法,如图像处理、特征检测、目标检测、人脸识别等。同时,Opencv也支持深度学习,可以用于图像分、目标检测、语义分割等任务。以下是一些C++ Opencv深度学习的例子: 1. 使用Opencv进行图像分 ```c++ #include <opencv2/opencv.hpp> #include <opencv2/dnn.hpp> #include <iostream> using namespace cv; using namespace cv::dnn; using namespace std; int main() { // 加载模型和标签 Net net = readNetFromCaffe("deploy.prototxt", "model.caffemodel"); string label[10] = {"airplane", "automobile", "bird", "cat", "deer", "dog", "frog", "horse", "ship", "truck"}; // 加载图像 Mat img = imread("test.jpg"); // 图像预处理 Mat inputBlob = blobFromImage(img, 1.0, Size(32, 32), Scalar(104, 117, 123), false, false); // 输入模型进行预测 net.setInput(inputBlob, "data"); Mat prob = net.forward("prob"); // 输出预测结果 Point classIdPoint; double confidence; minMaxLoc(prob.reshape(1, 1), 0, &confidence, 0, &classIdPoint); int classId = classIdPoint.x; cout << "Predicted class: " << label[classId] << endl; cout << "Confidence: " << confidence << endl; return 0; } ``` 2. 使用Opencv进行目标检测 ```c++ #include <opencv2/opencv.hpp> #include <opencv2/dnn.hpp> #include <iostream> using namespace cv; using namespace cv::dnn; using namespace std; int main() { // 加载模型和标签 Net net = readNetFromCaffe("deploy.prototxt", "model.caffemodel"); string label[21] = {"background", "aeroplane", "bicycle", "bird", "boat", "bottle", "bus", "car", "cat", "chair", "cow", "diningtable", "dog", "horse", "motorbike", "person", "pottedplant", "sheep", "sofa", "train", "tvmonitor"}; // 加载图像 Mat img = imread("test.jpg"); // 图像预处理 Mat inputBlob = blobFromImage(img, 0.007843, Size(300, 300), Scalar(127.5, 127.5, 127.5), false, false); // 输入模型进行预测 net.setInput(inputBlob, "data"); Mat detection = net.forward("detection_out"); // 输出预测结果 Mat detectionMat(detection.size[2], detection.size[3], CV_32F, detection.ptr<float>()); for (int i = 0; i < detectionMat.rows; i++) { float confidence = detectionMat.at<float>(i, 2); if (confidence > 0.5) { int classId = (int)(detectionMat.at<float>(i, 1)); int left = (int)(detectionMat.at<float>(i, 3) * img.cols); int top = (int)(detectionMat.at<float>(i, 4) * img.rows); int right = (int)(detectionMat.at<float>(i, 5) * img.cols); int bottom = (int)(detectionMat.at<float>(i, 6) * img.rows); rectangle(img, Point(left, top), Point(right, bottom), Scalar(0, 255, 0), 2); putText(img, label[classId], Point(left, top - 5), FONT_HERSHEY_SIMPLEX, 0.5, Scalar(0, 255, 0), 2); } } // 显示结果 imshow("result", img); waitKey(0); return 0; } ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值