Posts

Showing posts from July, 2019

OpenCV Programming 1

1. Display data type. #include "pch.h" #include <opencv2/highgui/highgui.hpp> #include <opencv2/imgproc.hpp> #include <iostream> using namespace cv; using namespace std; int main(int argc, char** argv) { int i = 2; while (i != 0) { cout << "enter image martix size"; cin >> i; if (i == -1) { break; } Mat M(i, i, CV_8UC3, Scalar(0, 0, 255)); cout << "M = " << endl << " " << M << endl << endl; } }

Opencv Mat

OpenCV has been around since 2001. In those days the library was built around a C interface and to store the image in the memory they used a C structure called IplImage C interface Store image IplImage Memory leakage issues. Memory leakage issues  over come by C++ Luckily C++ came around and introduced the concept of classes making easier for the user through automatic memory management https://docs.opencv.org/2.4/doc/tutorials/core/mat_the_basic_image_container/mat_the_basic_image_container.html

Opencv Drawing Functions

Drawing Functions https://docs.opencv.org/3.0-beta/modules/imgproc/doc/drawing_functions.html header for Drawing functions: imgproc.hpp Mat image(200, 200, CV_8UC3, Scalar(0)); RotatedRect rRect = RotatedRect(Point2f(100, 100), Size2f(100, 50), 30); Point2f vertices[4]; rRect.points(vertices); for (int i = 0; i < 4; i++) line(image, vertices[i], vertices[(i + 1) % 4], Scalar(0, 255, 0),1); Rect brect = rRect.boundingRect(); rectangle(image, brect, Scalar(255, 0, 0)); imshow("rectangles", image); waitKey(0);

Open CV Url

C++: Tutorial http://www.cplusplus.com/reference/type_traits/ Open CV introduction: https://www.opencv-srf.com/2017/11/load-and-display-image.html https://medium.com/@ariesiitr/image-processing-with-opencv-45c3a5cefd10

Example Intro 100: Display image.

#include "pch.h" #include <opencv2/highgui/highgui.hpp> #include <iostream> using namespace cv; using namespace std; int main(int argc, char** argv) { if (argc != 2) { cout << " Usage: display_image ImageToLoadAndDisplay" << endl; return -1; } Mat image; String value = argv[1]; image = imread(argv[1], IMREAD_COLOR);   // Read the file if (!image.data)                              // Check for invalid input { cout << "Could not open or find the image" << std::endl; return -1; } namedWindow("Display window", WINDOW_AUTOSIZE);// Create a window for display. imshow("Display window", image);                   // Show our image inside it. waitKey(0);                                          // Wait for a keystroke in the window return 0; } https://docs.opencv.org/3.0-beta/doc/py_tutorials/py_gui/py_image_display/py_image_display.html