Article directory
Preface
Because Lao Wang and I want to switch to the computer industry in the direction of machine vision, I plan to start learning OpenCV from scratch. But currently OpenCV has two official languages, C++ and Python. In C#, some experts have adapted the corresponding OpenCV version. The current characteristics of the three languages are
- C++: The fastest running efficiency, but the syntax is extremely difficult and the development is extremely difficult
- Python: The development efficiency is extremely fast, but the running efficiency is extremely slow. If it is not well optimized, it is more than 20 times slower than C++.
- C#: The development efficiency is fast, not much slower than Python, and the running efficiency is lower than C++. But there are few tutorials related to OpenCV
Which image processing language has better prospects: python, C++, Matlab or Opencv?
So I made a difficult but correct decision to develop three languages at the same time! In fact, it is just three languages developing the same function together.
Course selection
I am currently searching for tutorials on site B and found two tutorials with the highest views. If you are learning from scratch, it is still recommended to go through the video, because you need to understand many configuration details and compiler operations. The goal in this period is that the code can run through, which is victory.
OpenCV4 C++ Quick Start Video 30 Lectures - Series Collection
There are two classes in total, one in Python and one in C++. As a developer, I definitely take the C++ course first, because C++ is the most difficult one as long as you can run it.
Environment configuration
Python
I have configured it before, so I will put the link directly here.
Python+OpenCV zero-based study notes (1-3): anaconda+vscode+jupyter environment configuration
C#
I've done it in C# too
C++
This time I will mainly talk about C++
OpenCV installation and development environment configuration (C++)
OpenCV official website download
After downloading, unzip it
Create a new C++ project
test run
I copied this code from someone else's
OpenCV installation and development environment configuration (C++)
#include <opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include<iostream>
using namespace std;
using namespace cv;
int main()
{
Mat image = Mat::zeros(300, 600, CV_8UC3);
circle(image, Point(300, 200), 100, Scalar(25, 110, 288), -100);
circle(image, Point(400, 200), 100, Scalar(255, 123, 127), -100);
imshow("Show Window", image);
waitKey(0);
return 0;
}
If the following picture appears, the operation is successful
Csharp version
static void Main(string[] args)
{
Mat image = new Mat(300,600,MatType.CV_8UC3);
image.Circle(new Point(300, 200), 100, new Scalar(25, 110, 288), -100);
image.Circle(new Point(400, 200), 100, new Scalar(255, 123, 127), -100);
Cv2.ImShow("Show Window",image);
Cv2.WaitKey(0);
//Console.WriteLine("Hello, World!");
Console.ReadKey();
}
Python version
Python is completely different from other codes. The naming logic of C++ and Csharp is basically the same, but Python is a bit unique.
After searching online for a long time, I finally found out how to draw. I don’t know if Python and C++ are essentially the same, but the results shown are similar.
import cv2
# python中需要np来辅助
import numpy as np
image =np.zeros((300, 600, 3), np.uint8)
cv2.circle(image,(300,200),100,(25,110,288),-100);
cv2.circle(image,(400,200),100,(255,123,127),-100);
cv2.imshow("Show Window",image)
cv2.waitKey(0)
gitee warehouse
I created a new warehouse, but it doesn't feel like it makes much sense. Due to the difference in library management of the three files, the global libraries of C++ and Python, and Csharp are independent libraries for each project. So it is troublesome to create new projects frequently. I won’t create a new project here, just paste the code and use it.
Summarize
This time I just installed the OpenCV environment. Next time I will go back to learn how to correctly use three languages to write OpenCV.