Difference between revisions of "OpenCV/WishList/IO/WriteMatrix"
From ProgrammingExamples
< OpenCV
Daviddoria (Talk | contribs) (Created page with '==WriteMatrix.cxx== <source lang="cpp"> #include "cv.h" #include "opencv2/highgui/highgui.hpp" #include <iostream> int main(int argc, char*argv[]) { cv::Mat myMatrix(3,3,CV_3…') |
Daviddoria (Talk | contribs) |
||
Line 8: | Line 8: | ||
int main(int argc, char*argv[]) | int main(int argc, char*argv[]) | ||
{ | { | ||
− | cv::Mat myMatrix(3,3, | + | cv::Mat myMatrix(3,3,CV_32FC1); |
std::cout << "Input:" << std::endl; | std::cout << "Input:" << std::endl; | ||
for(unsigned int i = 0; i < 3; i++) | for(unsigned int i = 0; i < 3; i++) | ||
Line 14: | Line 14: | ||
for(unsigned int j = 0; j < 3; j++) | for(unsigned int j = 0; j < 3; j++) | ||
{ | { | ||
− | + | myMatrix.at<float>(i,j) = 2.1; | |
− | + | ||
− | + | ||
− | + | ||
− | myMatrix.at< | + | |
} | } | ||
} | } | ||
Line 25: | Line 21: | ||
cv::imwrite("matrix.jpg", myMatrix); | cv::imwrite("matrix.jpg", myMatrix); | ||
− | + | ||
− | cv::Mat inputMatrix = cv::imread("matrix.jpg", | + | // Doesn't work - the matrix that is read back in has been rounded to integers! |
+ | cv::Mat inputMatrix = cv::imread("matrix.jpg", 0); | ||
std::cout << inputMatrix << std::endl; | std::cout << inputMatrix << std::endl; | ||
Line 32: | Line 29: | ||
return 0; | return 0; | ||
} | } | ||
+ | |||
Revision as of 11:04, 21 January 2011
WriteMatrix.cxx
#include "cv.h" #include "opencv2/highgui/highgui.hpp" #include <iostream> int main(int argc, char*argv[]) { cv::Mat myMatrix(3,3,CV_32FC1); std::cout << "Input:" << std::endl; for(unsigned int i = 0; i < 3; i++) { for(unsigned int j = 0; j < 3; j++) { myMatrix.at<float>(i,j) = 2.1; } } std::cout << myMatrix << std::endl; cv::imwrite("matrix.jpg", myMatrix); // Doesn't work - the matrix that is read back in has been rounded to integers! cv::Mat inputMatrix = cv::imread("matrix.jpg", 0); 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 )