opencv矩阵的用法

矩阵的初始化及赋值

        cv::Mat grid1(5, 5, CV_32SC1, cv::Scalar(0));
		grid1.at<int>(0, 0) = 1;   grid1.at<int>(0, 1) = 1;
		grid1.at<int>(2, 3) = 1;
		grid1.at<int>(3, 4) = 1;  grid1.at<int>(3, 3) = 1;
		grid1.at<int>(4, 4) = 1;

矩阵指针的形式

        cv::Mat* grid3 = new cv::Mat (5, 5, CV_32SC1, cv::Scalar(0));
		(*grid3).at<int>(0, 0) = 1; (*grid3).at<int>(0, 1) = 1; (*grid3).at<int>(0, 3) = 1;
		(*grid3).at<int>(1, 0) = 1; (*grid3).at<int>(1, 4) = 1;
		(*grid3).at<int>(3, 0) = 1; (*grid3).at<int>(3, 1) = 1; (*grid3).at<int>(3, 2) = 1;
		(*grid3).at<int>(4, 2) = 1; (*grid3).at<int>(4, 4) = 1;```
 cv::Mat *edgemat = new cv::Mat(index_row, index_col,CV_32SC1, cv::Scalar(0));

局部时间窗计算干涉矩阵:对于new的指针用完之后要删除

void TimeWindowTrajectories::CalculateMat(int cur_agv_idx, const EdgesVec& cur_routes, int other_agv_idx, const EdgesVec& other_routes)
	{
		auto cur_agv = getAgent(cur_agv_idx);
		auto other_agv = getAgent(other_agv_idx);
		auto cur_agv_routes = cur_routes;
		auto other_agv_routes = other_routes;
		int index_row = other_agv_routes.size();
		int index_col = cur_agv_routes.size();
		//当前车路径对应的列,其他车的路径对应的行
		cv::Mat *edgemat = new cv::Mat(index_row, index_col,CV_32SC1, cv::Scalar(0));
		for (int i = 0; i < index_row; i++)
		{
			for (int j = 0; j < index_col; j++)
			{
				//(1)判断边与边
				if (other_agv_routes[i]->clashWith(cur_agv_routes[j]))
				{
					edgemat->at<int32_t>(i, j) = 1;
				}								
			}
		}
		AGVMatInfo agvMatInfo;		
 		agvMatInfo.mat = edgemat;
		agvMatInfo.otherAGVIdx = other_agv_idx;
		agvMatInfo.otherAGVroutes = other_routes;
		agvMatInfo.curAGVIdx = cur_agv_idx;
		agvMatInfo.curAGVroutes = cur_routes;
 		cur_agv->agvMatinfo.push_back(agvMatInfo); 
		delete edgemat;
	}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值