Horizontal Bar Chart in OpenCV

I am new to OpenCV, now I am working on a senior project related to image processing. My question is: can I make a horizontal or vertical histogram with some OpenCV features? Thank,

Truonga

+3
source share
4 answers

The most efficient way to do this is to use cvReduce . There is a parameter that allows you to choose whether you want horizontal or vertical projection.

You can also do this manually with the cvGetCol and cvGetRow functions in combination with cvSum .

+5
source

, , , .

n , n - . n- n- .

, , cvGetSubRect , cvSum .

Python, , :

import cv

def verticalProjection(img):
    "Return a list containing the sum of the pixels in each column"
    (w,h) = cv.GetSize(img)
    sumCols = []
    for j in range(w):
        col = cv.GetSubRect(img, (j,0,1,h))
        sumCols.append(cv.Sum(col)[0])
    return sumCols
+1

carnieri ( cv )

import numpy as np
import cv2

def verticalProjection(img):
    "Return a list containing the sum of the pixels in each column"
    (h, w) = img.shape[:2]
    sumCols = []
    for j in range(w):
        col = img[0:h, j:j+1] # y1:y2, x1:x2
        sumCols.append(np.sum(col))
    return sumCols

.

+1

cv2.reduce OpenCV 3 Python:

import numpy as np
import cv2

img = cv2.imread("test_1.png") 

x_sum = cv2.reduce(img, 0, cv2.REDUCE_SUM, dtype=cv2.CV_32S) 
y_sum = cv2.reduce(img, 1, cv2.REDUCE_SUM, dtype=cv2.CV_32S) 
0

Source: https://habr.com/ru/post/1777247/


All Articles