Skip to content

Instantly share code, notes, and snippets.

@Mikayex
Created January 21, 2015 21:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mikayex/d2bce3af3af675cf4549 to your computer and use it in GitHub Desktop.
Save Mikayex/d2bce3af3af675cf4549 to your computer and use it in GitHub Desktop.
Démonstration openCV
#include <cstdlib>
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main(int argc, char** argv) {
Size2i imageSize(200, 200);
Scalar red(0, 0, 255), blue(255, 0, 0);
//Red image creation
Mat redImg(imageSize, CV_8UC3);
redImg.setTo(red);
imshow("Red image", redImg);
imwrite("Red image.png", redImg);
//Red image creation
Mat blueImg(imageSize, CV_8UC3);
blueImg.setTo(blue);
imshow("Blue image", blueImg);
imwrite("Blue image.png", blueImg);
//Red image with blue rectangle
Mat rectImg(imageSize, CV_8UC3);
rectImg.setTo(red);
rectangle(rectImg, Rect(50, 50, 100, 60), blue, CV_FILLED);
imshow("Rectangle image", rectImg);
imwrite("Rectangle image.png", rectImg);
//Vector definition
Vec3f V1(1.5, 2.1, 3), V2(0, 0, 1), V3(0.5, 0.5, 0.5);
cout << "V1=" << V1 << endl;
cout << "V2=" << V2 << endl;
cout << "V3=" << V3 << endl;
cout << "V1.V2=" << V1.dot(V2) << endl; //Should be 3
cout << "V2.V3=" << V2.dot(V3) << endl; //Should be 0.5
cout << "V1^V2=" << V1.cross(V2) << endl; //Should be (2.1, -1.5, 0)
cout << "V2^V3=" << V2.cross(V3) << endl; //Should be (-0.5, 0.5, 0)
Matx33f M(1, 0.5, 0.75,
0, 2, 0,
3, 0, 0);
cout << "M=" << M << endl;
cout << "M*V1=" << M * V1 << endl; //Should be (4.8, 4.2, 4.5)
cout << "M*V2=" << M * V2 << endl; //Should be (0.75, 0, 0)
Matx33f M2(1, 1, 1,
3, 0, 5,
0, 2.8, 1.4);
Matx33f M3 = M*M2;
cout << "M2=" << M2 << endl;
/* Should be
[2.5, 3.1, 4.55;
6, 0, 10;
3, 3, 3] */
cout << "M3=" << M3 << endl;
waitKey(0);
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment