赞
踩
1、利用数组中的数生成像素点。
std::vector<cv::Point> mypattern;
std::vector<cv::Point> mypattern2;
static int bit[10]
={25,5,25,12,22,17,0,5,1,12};
const Point* pattern1 = (const Point*)bit;
std::copy(pattern1, pattern1 + 3, std::back_inserter(mypattern));
std::copy(pattern1+3, pattern1 + 5, std::back_inserter(mypattern2));
mypattern[0].x为25,mypattern[0].y为5。
mypattern2[0].x为0,mypattern2[0].y为5。
2、在图像上画网格
#include <opencv2/core.hpp> #include <opencv2/imgproc.hpp> #include <opencv2/highgui.hpp> using namespace std; using namespace cv; int main (){ Mat image=imread("./1.png"); int y=image.rows; int x=image.cols; int dx=x/20;//x轴间隔 int dy=y/20;//y轴间隔 for(int i=dx;i<x-1;i+=dx){//画竖线,第一个point是线的起始点,第二个是线的终点,2是线的粗细,LINE_8是线的形状 line(image,Point(i,0),Point(i,y-1),Scalar(0,0,0),2,LINE_8); } for(int j=dy;j<y-1;j+=dy){//画横线 line(image,Point(0,j),Point(x-1,j),Scalar(0,0,0),2,LINE_8); } imshow("image",image); waitKey(0); return 0; }
3、创建高斯核
https://blog.csdn.net/u012633319/article/details/80921023
创建3*3,均方差为1.2的高斯核G
Mat kernelX = getGaussianKernel(3, 1.2);
cout << kernelX << endl;
Mat kernelY = getGaussianKernel(3, 1.2);
Mat G = kernelX * kernelY.t();
cout << G << endl;
2、二维高斯函数:
制作3*3高斯滤波器,把下图的坐标带入上式
得到:
这9个点的权重总和等于0.4787147,如果只计算这9个点的加权平均,还必须让它们的权重之和等于1,因此上面9个值还要分别除以0.4787147,得到最终的权重矩阵:
4、生成棋盘格
# -*- coding:utf-8 -*- import cv2 import numpy as np def generatePattern(CheckerboardSize, Nx_cor, Ny_cor): ''' 自定义生成棋盘 :param CheckerboardSize: 棋盘格大小,此处100即可 :param Nx_cor: 棋盘格横向内角数 :param Ny_cor: 棋盘格纵向内角数 :return: ''' black = np.zeros((CheckerboardSize, CheckerboardSize, 3), np.uint8) white = np.zeros((CheckerboardSize, CheckerboardSize, 3), np.uint8) black[:] = [0, 0, 0] # 纯黑色 white[:] = [255, 255, 255] # 纯白色 black_white = np.concatenate([black, white], axis=1) black_white2 = black_white white_black = np.concatenate([white, black], axis=1) white_black2 = white_black # 横向连接 if Nx_cor % 2 == 1: for i in range(1, (Nx_cor+1) // 2): black_white2 = np.concatenate([black_white2, black_white], axis=1) white_black2 = np.concatenate([white_black2, white_black], axis=1) else: for i in range(1, Nx_cor // 2): black_white2 = np.concatenate([black_white2, black_white], axis=1) white_black2 = np.concatenate([white_black2, white_black], axis=1) black_white2 = np.concatenate([black_white2, black], axis=1) white_black2 = np.concatenate([white_black2, white], axis=1) jj = 0 black_white3 = black_white2 for i in range(0, Ny_cor): jj += 1 # 纵向连接 if jj % 2 == 1: black_white3 = np.concatenate((black_white3, white_black2)) # =np.vstack((img1, img2)) else: black_white3 = np.concatenate((black_white3, black_white2)) # =np.vstack((img1, img2)) cv2.imshow('', black_white3) cv2.imwrite('pattern.jpg', black_white3) cv2.waitKey(5000) cv2.destroyAllWindows() if __name__ == '__main__': generatePattern(100, 9, 6)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。