opencv-從映像旋轉學習Mat資料訪問

來源:互聯網
上載者:User

標籤:opencv

先看一個簡單的例子


代碼:

// ConsoleApplication3_6_23.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include<opencv2/opencv.hpp>#include<iostream>#include<vector>using namespace std;using namespace cv;int _tmain(int argc, _TCHAR* argv[]){Mat src,dst,dst1,dst2;src = imread("test.png");if(!src.data)return -1;namedWindow("原圖",CV_WINDOW_AUTOSIZE);namedWindow("x--",CV_WINDOW_AUTOSIZE);namedWindow("y--",CV_WINDOW_AUTOSIZE);imshow("原圖",src);int nr = src.rows;int nc = src.cols;/************************************************************************//* x方向                                                                     *//************************************************************************/dst = src.clone();for (int i = 0;i < nr;++i){for (int j = 0;j < nc;++j){dst.at<Vec3b>(i,j) = src.at<Vec3b>(i,nc-j-1);}}imshow("x--",dst);/************************************************************************//* y方向                                                                     *//************************************************************************/src.copyTo(dst1);for (int i = 0;i < nr;++i){for (int j = 0;j < nc;++j){dst1.at<Vec3b>(i,j) = src.at<Vec3b>(nr-i-1,j);}}imshow("y--",dst1);waitKey(0);return 0;}

1、Mat的ptr和[]

void image_rever(Mat& src,Mat& dst){int nr = src.rows;int nc = src.cols;int ch = src.channels();for (int i = 0;i < nr;++i){uchar* srcr = src.ptr<uchar>(i);uchar* dstr = dst.ptr<uchar>(i);for (int j = 0;j < nc;++j){dstr[ch * j + 0] = srcr[ch * (nc - j - 1) + 0];dstr[ch * j + 1] = srcr[ch * (nc - j - 1) + 1];dstr[ch * j + 2] = srcr[ch * (nc - j - 1) + 2];}}}



相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.