feat: 切换后端至PaddleOCR-NCNN,切换工程为CMake
1.项目后端整体迁移至PaddleOCR-NCNN算法,已通过基本的兼容性测试 2.工程改为使用CMake组织,后续为了更好地兼容第三方库,不再提供QMake工程 3.重整权利声明文件,重整代码工程,确保最小化侵权风险 Log: 切换后端至PaddleOCR-NCNN,切换工程为CMake Change-Id: I4d5d2c5d37505a4a24b389b1a4c5d12f17bfa38c
This commit is contained in:
@ -0,0 +1,71 @@
|
||||
from __future__ import print_function
|
||||
from __future__ import division
|
||||
import cv2 as cv
|
||||
import numpy as np
|
||||
import argparse
|
||||
|
||||
def Hist_and_Backproj(val):
|
||||
## [initialize]
|
||||
bins = val
|
||||
histSize = max(bins, 2)
|
||||
ranges = [0, 180] # hue_range
|
||||
## [initialize]
|
||||
|
||||
## [Get the Histogram and normalize it]
|
||||
hist = cv.calcHist([hue], [0], None, [histSize], ranges, accumulate=False)
|
||||
cv.normalize(hist, hist, alpha=0, beta=255, norm_type=cv.NORM_MINMAX)
|
||||
## [Get the Histogram and normalize it]
|
||||
|
||||
## [Get Backprojection]
|
||||
backproj = cv.calcBackProject([hue], [0], hist, ranges, scale=1)
|
||||
## [Get Backprojection]
|
||||
|
||||
## [Draw the backproj]
|
||||
cv.imshow('BackProj', backproj)
|
||||
## [Draw the backproj]
|
||||
|
||||
## [Draw the histogram]
|
||||
w = 400
|
||||
h = 400
|
||||
bin_w = int(round(w / histSize))
|
||||
histImg = np.zeros((h, w, 3), dtype=np.uint8)
|
||||
|
||||
for i in range(bins):
|
||||
cv.rectangle(histImg, (i*bin_w, h), ( (i+1)*bin_w, h - int(np.round( hist[i]*h/255.0 )) ), (0, 0, 255), cv.FILLED)
|
||||
|
||||
cv.imshow('Histogram', histImg)
|
||||
## [Draw the histogram]
|
||||
|
||||
## [Read the image]
|
||||
parser = argparse.ArgumentParser(description='Code for Back Projection tutorial.')
|
||||
parser.add_argument('--input', help='Path to input image.', default='home.jpg')
|
||||
args = parser.parse_args()
|
||||
|
||||
src = cv.imread(cv.samples.findFile(args.input))
|
||||
if src is None:
|
||||
print('Could not open or find the image:', args.input)
|
||||
exit(0)
|
||||
## [Read the image]
|
||||
|
||||
## [Transform it to HSV]
|
||||
hsv = cv.cvtColor(src, cv.COLOR_BGR2HSV)
|
||||
## [Transform it to HSV]
|
||||
|
||||
## [Use only the Hue value]
|
||||
ch = (0, 0)
|
||||
hue = np.empty(hsv.shape, hsv.dtype)
|
||||
cv.mixChannels([hsv], [hue], ch)
|
||||
## [Use only the Hue value]
|
||||
|
||||
## [Create Trackbar to enter the number of bins]
|
||||
window_image = 'Source image'
|
||||
cv.namedWindow(window_image)
|
||||
bins = 25
|
||||
cv.createTrackbar('* Hue bins: ', window_image, bins, 180, Hist_and_Backproj )
|
||||
Hist_and_Backproj(bins)
|
||||
## [Create Trackbar to enter the number of bins]
|
||||
|
||||
## [Show the image]
|
||||
cv.imshow(window_image, src)
|
||||
cv.waitKey()
|
||||
## [Show the image]
|
@ -0,0 +1,79 @@
|
||||
from __future__ import print_function
|
||||
import cv2 as cv
|
||||
import numpy as np
|
||||
import argparse
|
||||
|
||||
low = 20
|
||||
up = 20
|
||||
|
||||
def callback_low(val):
|
||||
global low
|
||||
low = val
|
||||
|
||||
def callback_up(val):
|
||||
global up
|
||||
up = val
|
||||
|
||||
def pickPoint(event, x, y, flags, param):
|
||||
if event != cv.EVENT_LBUTTONDOWN:
|
||||
return
|
||||
|
||||
# Fill and get the mask
|
||||
seed = (x, y)
|
||||
newMaskVal = 255
|
||||
newVal = (120, 120, 120)
|
||||
connectivity = 8
|
||||
flags = connectivity + (newMaskVal << 8 ) + cv.FLOODFILL_FIXED_RANGE + cv.FLOODFILL_MASK_ONLY
|
||||
|
||||
mask2 = np.zeros((src.shape[0] + 2, src.shape[1] + 2), dtype=np.uint8)
|
||||
print('low:', low, 'up:', up)
|
||||
cv.floodFill(src, mask2, seed, newVal, (low, low, low), (up, up, up), flags)
|
||||
mask = mask2[1:-1,1:-1]
|
||||
|
||||
cv.imshow('Mask', mask)
|
||||
Hist_and_Backproj(mask)
|
||||
|
||||
def Hist_and_Backproj(mask):
|
||||
h_bins = 30
|
||||
s_bins = 32
|
||||
histSize = [h_bins, s_bins]
|
||||
h_range = [0, 180]
|
||||
s_range = [0, 256]
|
||||
ranges = h_range + s_range # Concat list
|
||||
channels = [0, 1]
|
||||
|
||||
# Get the Histogram and normalize it
|
||||
hist = cv.calcHist([hsv], channels, mask, histSize, ranges, accumulate=False)
|
||||
cv.normalize(hist, hist, alpha=0, beta=255, norm_type=cv.NORM_MINMAX)
|
||||
|
||||
# Get Backprojection
|
||||
backproj = cv.calcBackProject([hsv], channels, hist, ranges, scale=1)
|
||||
|
||||
# Draw the backproj
|
||||
cv.imshow('BackProj', backproj)
|
||||
|
||||
# Read the image
|
||||
parser = argparse.ArgumentParser(description='Code for Back Projection tutorial.')
|
||||
parser.add_argument('--input', help='Path to input image.', default='home.jpg')
|
||||
args = parser.parse_args()
|
||||
|
||||
src = cv.imread(cv.samples.findFile(args.input))
|
||||
if src is None:
|
||||
print('Could not open or find the image:', args.input)
|
||||
exit(0)
|
||||
|
||||
# Transform it to HSV
|
||||
hsv = cv.cvtColor(src, cv.COLOR_BGR2HSV)
|
||||
|
||||
# Show the image
|
||||
window_image = 'Source image'
|
||||
cv.namedWindow(window_image)
|
||||
cv.imshow(window_image, src)
|
||||
|
||||
# Set Trackbars for floodfill thresholds
|
||||
cv.createTrackbar('Low thresh', window_image, low, 255, callback_low)
|
||||
cv.createTrackbar('High thresh', window_image, up, 255, callback_up)
|
||||
# Set a Mouse Callback
|
||||
cv.setMouseCallback(window_image, pickPoint)
|
||||
|
||||
cv.waitKey()
|
@ -0,0 +1,71 @@
|
||||
from __future__ import print_function
|
||||
from __future__ import division
|
||||
import cv2 as cv
|
||||
import numpy as np
|
||||
import argparse
|
||||
|
||||
## [Load image]
|
||||
parser = argparse.ArgumentParser(description='Code for Histogram Calculation tutorial.')
|
||||
parser.add_argument('--input', help='Path to input image.', default='lena.jpg')
|
||||
args = parser.parse_args()
|
||||
|
||||
src = cv.imread(cv.samples.findFile(args.input))
|
||||
if src is None:
|
||||
print('Could not open or find the image:', args.input)
|
||||
exit(0)
|
||||
## [Load image]
|
||||
|
||||
## [Separate the image in 3 places ( B, G and R )]
|
||||
bgr_planes = cv.split(src)
|
||||
## [Separate the image in 3 places ( B, G and R )]
|
||||
|
||||
## [Establish the number of bins]
|
||||
histSize = 256
|
||||
## [Establish the number of bins]
|
||||
|
||||
## [Set the ranges ( for B,G,R) )]
|
||||
histRange = (0, 256) # the upper boundary is exclusive
|
||||
## [Set the ranges ( for B,G,R) )]
|
||||
|
||||
## [Set histogram param]
|
||||
accumulate = False
|
||||
## [Set histogram param]
|
||||
|
||||
## [Compute the histograms]
|
||||
b_hist = cv.calcHist(bgr_planes, [0], None, [histSize], histRange, accumulate=accumulate)
|
||||
g_hist = cv.calcHist(bgr_planes, [1], None, [histSize], histRange, accumulate=accumulate)
|
||||
r_hist = cv.calcHist(bgr_planes, [2], None, [histSize], histRange, accumulate=accumulate)
|
||||
## [Compute the histograms]
|
||||
|
||||
## [Draw the histograms for B, G and R]
|
||||
hist_w = 512
|
||||
hist_h = 400
|
||||
bin_w = int(round( hist_w/histSize ))
|
||||
|
||||
histImage = np.zeros((hist_h, hist_w, 3), dtype=np.uint8)
|
||||
## [Draw the histograms for B, G and R]
|
||||
|
||||
## [Normalize the result to ( 0, histImage.rows )]
|
||||
cv.normalize(b_hist, b_hist, alpha=0, beta=hist_h, norm_type=cv.NORM_MINMAX)
|
||||
cv.normalize(g_hist, g_hist, alpha=0, beta=hist_h, norm_type=cv.NORM_MINMAX)
|
||||
cv.normalize(r_hist, r_hist, alpha=0, beta=hist_h, norm_type=cv.NORM_MINMAX)
|
||||
## [Normalize the result to ( 0, histImage.rows )]
|
||||
|
||||
## [Draw for each channel]
|
||||
for i in range(1, histSize):
|
||||
cv.line(histImage, ( bin_w*(i-1), hist_h - int(b_hist[i-1]) ),
|
||||
( bin_w*(i), hist_h - int(b_hist[i]) ),
|
||||
( 255, 0, 0), thickness=2)
|
||||
cv.line(histImage, ( bin_w*(i-1), hist_h - int(g_hist[i-1]) ),
|
||||
( bin_w*(i), hist_h - int(g_hist[i]) ),
|
||||
( 0, 255, 0), thickness=2)
|
||||
cv.line(histImage, ( bin_w*(i-1), hist_h - int(r_hist[i-1]) ),
|
||||
( bin_w*(i), hist_h - int(r_hist[i]) ),
|
||||
( 0, 0, 255), thickness=2)
|
||||
## [Draw for each channel]
|
||||
|
||||
## [Display]
|
||||
cv.imshow('Source image', src)
|
||||
cv.imshow('calcHist Demo', histImage)
|
||||
cv.waitKey()
|
||||
## [Display]
|
@ -0,0 +1,69 @@
|
||||
from __future__ import print_function
|
||||
from __future__ import division
|
||||
import cv2 as cv
|
||||
import numpy as np
|
||||
import argparse
|
||||
|
||||
## [Load three images with different environment settings]
|
||||
parser = argparse.ArgumentParser(description='Code for Histogram Comparison tutorial.')
|
||||
parser.add_argument('--input1', help='Path to input image 1.')
|
||||
parser.add_argument('--input2', help='Path to input image 2.')
|
||||
parser.add_argument('--input3', help='Path to input image 3.')
|
||||
args = parser.parse_args()
|
||||
|
||||
src_base = cv.imread(args.input1)
|
||||
src_test1 = cv.imread(args.input2)
|
||||
src_test2 = cv.imread(args.input3)
|
||||
if src_base is None or src_test1 is None or src_test2 is None:
|
||||
print('Could not open or find the images!')
|
||||
exit(0)
|
||||
## [Load three images with different environment settings]
|
||||
|
||||
## [Convert to HSV]
|
||||
hsv_base = cv.cvtColor(src_base, cv.COLOR_BGR2HSV)
|
||||
hsv_test1 = cv.cvtColor(src_test1, cv.COLOR_BGR2HSV)
|
||||
hsv_test2 = cv.cvtColor(src_test2, cv.COLOR_BGR2HSV)
|
||||
## [Convert to HSV]
|
||||
|
||||
## [Convert to HSV half]
|
||||
hsv_half_down = hsv_base[hsv_base.shape[0]//2:,:]
|
||||
## [Convert to HSV half]
|
||||
|
||||
## [Using 50 bins for hue and 60 for saturation]
|
||||
h_bins = 50
|
||||
s_bins = 60
|
||||
histSize = [h_bins, s_bins]
|
||||
|
||||
# hue varies from 0 to 179, saturation from 0 to 255
|
||||
h_ranges = [0, 180]
|
||||
s_ranges = [0, 256]
|
||||
ranges = h_ranges + s_ranges # concat lists
|
||||
|
||||
# Use the 0-th and 1-st channels
|
||||
channels = [0, 1]
|
||||
## [Using 50 bins for hue and 60 for saturation]
|
||||
|
||||
## [Calculate the histograms for the HSV images]
|
||||
hist_base = cv.calcHist([hsv_base], channels, None, histSize, ranges, accumulate=False)
|
||||
cv.normalize(hist_base, hist_base, alpha=0, beta=1, norm_type=cv.NORM_MINMAX)
|
||||
|
||||
hist_half_down = cv.calcHist([hsv_half_down], channels, None, histSize, ranges, accumulate=False)
|
||||
cv.normalize(hist_half_down, hist_half_down, alpha=0, beta=1, norm_type=cv.NORM_MINMAX)
|
||||
|
||||
hist_test1 = cv.calcHist([hsv_test1], channels, None, histSize, ranges, accumulate=False)
|
||||
cv.normalize(hist_test1, hist_test1, alpha=0, beta=1, norm_type=cv.NORM_MINMAX)
|
||||
|
||||
hist_test2 = cv.calcHist([hsv_test2], channels, None, histSize, ranges, accumulate=False)
|
||||
cv.normalize(hist_test2, hist_test2, alpha=0, beta=1, norm_type=cv.NORM_MINMAX)
|
||||
## [Calculate the histograms for the HSV images]
|
||||
|
||||
## [Apply the histogram comparison methods]
|
||||
for compare_method in range(4):
|
||||
base_base = cv.compareHist(hist_base, hist_base, compare_method)
|
||||
base_half = cv.compareHist(hist_base, hist_half_down, compare_method)
|
||||
base_test1 = cv.compareHist(hist_base, hist_test1, compare_method)
|
||||
base_test2 = cv.compareHist(hist_base, hist_test2, compare_method)
|
||||
|
||||
print('Method:', compare_method, 'Perfect, Base-Half, Base-Test(1), Base-Test(2) :',\
|
||||
base_base, '/', base_half, '/', base_test1, '/', base_test2)
|
||||
## [Apply the histogram comparison methods]
|
@ -0,0 +1,31 @@
|
||||
from __future__ import print_function
|
||||
import cv2 as cv
|
||||
import argparse
|
||||
|
||||
## [Load image]
|
||||
parser = argparse.ArgumentParser(description='Code for Histogram Equalization tutorial.')
|
||||
parser.add_argument('--input', help='Path to input image.', default='lena.jpg')
|
||||
args = parser.parse_args()
|
||||
|
||||
src = cv.imread(cv.samples.findFile(args.input))
|
||||
if src is None:
|
||||
print('Could not open or find the image:', args.input)
|
||||
exit(0)
|
||||
## [Load image]
|
||||
|
||||
## [Convert to grayscale]
|
||||
src = cv.cvtColor(src, cv.COLOR_BGR2GRAY)
|
||||
## [Convert to grayscale]
|
||||
|
||||
## [Apply Histogram Equalization]
|
||||
dst = cv.equalizeHist(src)
|
||||
## [Apply Histogram Equalization]
|
||||
|
||||
## [Display results]
|
||||
cv.imshow('Source image', src)
|
||||
cv.imshow('Equalized Image', dst)
|
||||
## [Display results]
|
||||
|
||||
## [Wait until user exits the program]
|
||||
cv.waitKey()
|
||||
## [Wait until user exits the program]
|
Reference in New Issue
Block a user