C++&Python&Csharp in OpenCV 专栏
【2022B站最好的OpenCV课程推荐】OpenCV从入门到实战 全套课程(附带课程课件资料+课件笔记)
ROI,本意是感兴趣区域。但是使用起来就和PS的截取部分区域差不多。
我之前写过一篇Python 的代码
Python+OpenCV 零基础学习笔记(6):ROI
其它的相关文章
OpenCV之感兴趣区域ROI(C++实现)
#include
#include
#include
#include
#include
using namespace std;
using namespace cv;
int main()
{
Mat image = imread("D:/workspace/program/OpenCV/c--csharp--python--open-cv/Resources/cat.png");
//截取图片,Range是范围,第一个是高度范围,第二个是宽度范围
Mat roi = image(Range(0,50),Range(0,200));
imshow("C++", roi);
waitKey(0);
destroyAllWindows();
return 0;
}
using OpenCvSharp;
namespace _1_HelloOpenCV
{
internal class Program
{
static void Main(string[] args)
{
Mat image = Cv2.ImRead("D:/workspace/program/OpenCV/c--csharp--python--open-cv/Resources/cat.png");
//Csharp里面都是方法,不能直接使用C++ 的变量当函数使用
Mat roi = image.SubMat(new OpenCvSharp.Range(0,50), new OpenCvSharp.Range(0, 200));
Cv2.ImShow("CSharp", roi);
Cv2.WaitKey(0);
Cv2.DestroyAllWindows();
//Console.WriteLine("Hello, World!");
Console.ReadKey();
}
}
}
#%%
import cv2
import matplotlib.pyplot as plt
import numpy as np
input_img={}
input_img['rgb'] = cv2.imread('Resource\cat.png')
# 截取ROI区域
input_img['roi'] = input_img['rgb'][0:50,0:200]
# 展示ROI区域
cv2.imshow('roi',input_img['roi'])
cv2.waitKey(0)
Opencv-C++笔记 (9) : opencv-多通道分离和合并
#include
#include
#include
#include
#include
using namespace std;
using namespace cv;
int main()
{
Mat image = imread("D:/workspace/program/OpenCV/c--csharp--python--open-cv/Resources/cat.png");
Mat bgr[3];
split(image,bgr);
imshow("C++ 蓝", bgr[0]);
imshow("C++ 绿", bgr[1]);
imshow("C++ 红", bgr[2]);
waitKey(0);
destroyAllWindows();
return 0;
}
using OpenCvSharp;
namespace _1_HelloOpenCV
{
internal class Program
{
static void Main(string[] args)
{
Mat image = Cv2.ImRead("D:/workspace/program/OpenCV/c--csharp--python--open-cv/Resources/cat.png");
//Csharp里面都是方法,不能直接使用C++ 的变量当函数使用
Mat[] bgr = new Mat[3];
bgr = Cv2.Split(image);
Cv2.ImShow("Csharp 蓝", bgr[0]);
Cv2.ImShow("Csharp 绿", bgr[1]);
Cv2.ImShow("Csharp 红", bgr[2]);
Cv2.WaitKey(0);
Cv2.DestroyAllWindows();
//Console.WriteLine("Hello, World!");
Console.ReadKey();
}
}
}
#%%
import cv2
import matplotlib.pyplot as plt
import numpy as np
input_img={}
input_img['rgb'] = cv2.imread('Resource\cat.png')
# 截取ROI区域
input_img['roi'] = input_img['rgb'][0:50,0:200]
# 展示ROI区域
# cv2.imshow('roi',input_img['roi'])
# 截取颜色通道
b,g,r = cv2.split(input_img['rgb'])
# 将RGB更新到字典中
input_img.update({
'r':r,
'g':g,
'b':b
})
# 展示BGR画面
cv2.imshow('b',input_img['b'])
cv2.imshow('g',input_img['g'])
cv2.imshow('r',input_img['r'])
cv2.waitKey(0)
cv2.destroyAllWindows()
#include
#include
#include
#include
#include
using namespace std;
using namespace cv;
int main()
{
Mat image = imread("D:/workspace/program/OpenCV/c--csharp--python--open-cv/Resources/cat.png");
Mat bgr[3];
split(image,bgr);
//imshow("C++ 蓝", bgr[0]);
//imshow("C++ 绿", bgr[1]);
//imshow("C++ 红", bgr[2]);
Mat imageMerge;
merge(bgr,3,imageMerge);
imshow("C++",imageMerge);
waitKey(0);
destroyAllWindows();
return 0;
}
using OpenCvSharp;
namespace _1_HelloOpenCV
{
internal class Program
{
static void Main(string[] args)
{
Mat image = Cv2.ImRead("D:/workspace/program/OpenCV/c--csharp--python--open-cv/Resources/cat.png");
//Csharp里面都是方法,不能直接使用C++ 的变量当函数使用
Mat[] bgr = new Mat[3];
bgr = Cv2.Split(image);
//Cv2.ImShow("Csharp 蓝", bgr[0]);
//Cv2.ImShow("Csharp 绿", bgr[1]);
//Cv2.ImShow("Csharp 红", bgr[2]);
Mat Merge = new Mat();
//很明显,CSharp的函数就好看懂的多
Cv2.Merge(bgr, Merge);
Cv2.ImShow("Csharp",Merge);
//Console.WriteLine("Hello, World!");
Cv2.WaitKey(0);
Cv2.DestroyAllWindows();
Console.ReadKey();
}
}
}
#%%
import cv2
import matplotlib.pyplot as plt
import numpy as np
input_img={}
input_img['rgb'] = cv2.imread('Resource\cat.png')
# 截取ROI区域
input_img['roi'] = input_img['rgb'][0:50,0:200]
# 展示ROI区域
# cv2.imshow('roi',input_img['roi'])
# 截取颜色通道
b,g,r = cv2.split(input_img['rgb'])
# 将RGB更新到字典中
input_img.update({
'r':r,
'g':g,
'b':b
})
# 展示BGR画面
# cv2.imshow('b',input_img['b'])
# cv2.imshow('g',input_img['g'])
# cv2.imshow('r',input_img['r'])
# 将BGR合并
input_img['merge']= cv2.merge((input_img['b'],input_img['g'],input_img['r']))
print(input_img['merge'])
cv2.imshow('merge',input_img['merge'])
cv2.waitKey(0)
cv2.destroyAllWindows()
后面我就是照着OpenCV Python的视频写代码了,所以之后会调整一下顺序,Python,C++,Csharp的顺序写代码了。
现在主要看的视频是这个视频。
【2022B站最好的OpenCV课程推荐】OpenCV从入门到实战 全套课程(附带课程课