OpenCV/WishList/IO/WriteMatrix

From ProgrammingExamples
< OpenCV
Revision as of 11:02, 21 January 2011 by Daviddoria (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

WriteMatrix.cxx

#include "cv.h"
#include "opencv2/highgui/highgui.hpp"
 
#include <iostream>
 
int main(int argc, char*argv[])
{
  cv::Mat myMatrix(3,3,CV_32FC3);
  std::cout << "Input:" << std::endl;
  for(unsigned int i = 0; i < 3; i++)
    {
    for(unsigned int j = 0; j < 3; j++)
      {
      cv::Point3f myPoint;
      myPoint.x = 1;
      myPoint.y = 2;
      myPoint.z = 3;
      myMatrix.at<cv::Point3f>(i,j) = myPoint;
      }
    }
 
  std::cout << myMatrix << std::endl;
 
  cv::imwrite("matrix.jpg", myMatrix);
 
  cv::Mat inputMatrix = cv::imread("matrix.jpg", 1);
 
  std::cout << inputMatrix << std::endl;
 
  return 0;
}

CMakeLists.txt

cmake_minimum_required(VERSION 2.6)
 
PROJECT(WriteMatrix)
 
FIND_PACKAGE(OpenCV REQUIRED )
INCLUDE_DIRECTORIES( ${OPENCV_INCLUDE_DIR} )
 
 
ADD_EXECUTABLE(WriteMatrix WriteMatrix.cxx)
TARGET_LINK_LIBRARIES(WriteMatrix opencv_core opencv_highgui
opencv_flann opencv_imgproc opencv_highgui opencv_ml opencv_video opencv_objdetect
          opencv_features2d opencv_calib3d opencv_legacy opencv_contrib
)