C++ int& 学习

587 篇文章 5 订阅 ¥99.90 ¥99.00

在C语言中 & 是取地址符号;

在C++中有 int& 这样的,这里的&不是取地址符号,而是引用符号;

引用是C++对C的一个补充;

变量的引用就是变量的别名,讲的通俗一点就是另外一个名字;

a的值为100,如果定义b为a的引用,b的值就是a的值;

定义的方式如下,

    int& b = a;    //定义b是a的引用

void CCjjyyView::OnDraw(CDC* pDC)
{
	CCjjyyDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
	CString str1;

	int a=101;
	int &b=a;//声明b是a的别名
	int &c=b;//声明c是b的别名
	int &d=a;//声明d是a的别名

	str1.Format("%d", a);
	pDC->TextOut(30, 30, str1);
	str1.Format("%d", b);
	pDC->TextOut(30, 60, str1);
	str1.Format("%d", c);
	pDC->TextOut(30, 90, str1);
	str1.Format("%d", d);
	pDC->TextOut(30, 120, str1);
}

定义了一个变量,再定义3个引用,输出值;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 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、付费专栏及课程。

余额充值