logo
down
shadow

using numpy.any to match color in opencv gives strange results


using numpy.any to match color in opencv gives strange results

By : Richard Gardner
Date : December 05 2020, 12:22 PM
it should still fix some issue You Don't need to over-complicate the problem by using numpy operations thrice. You may simply use cv2.inRange() and cv2.countNonZero() to get your job done. The above steps can be modulated to a method which you may call from your while loop to process each webcam frame.
code :
import cv2

def detect_color_blob(img_BGR, blob_color_BGR, tolerance, threshold):
    blob_color_lower = [blob_color_BGR[0] - tolerance, blob_color_BGR[1] - tolerance, blob_color_BGR[2] - tolerance]
    blob_color_upper = [blob_color_BGR[0] + tolerance, blob_color_BGR[1] + tolerance, blob_color_BGR[2] + tolerance]

    # Get a Binary Mask, where 255 => blob color found and 0=> blob color NOT found
    mask = cv2.inRange(img_BGR, blob_color_lower, blob_color_upper)

    # Check if the detected number of pixels is greater than threshold.
    return cv2.countNonZero(mask) > threshold


Share : facebook icon twitter icon
Strange OpenCV Distance Transform Results

Strange OpenCV Distance Transform Results


By : moin
Date : March 29 2020, 07:55 AM
wish help you to fix your issue One quick way to test your theory: try with a grey scale image that's muted (all values v --> 128+(v-128)/32 or something) and see if that makes the bands much wider or eliminates them completely.
It's always a good idea to nail down what the problem is first, and then try to fix it.
opencv zoom function strange results

opencv zoom function strange results


By : jack903
Date : March 29 2020, 07:55 AM
Any of those help cv.Resize requires source and destination to be separate memory locations.
Now in the first snippet of your code, you are using cv.GetSubRect to generate an object pointing to area of image which you wish to zoom in. Here the new object is NOT pointing to a new memory location. It is pointing to a memory location which is a subset of original object.
How to pass a numpy ndarray as a color in OpenCV?

How to pass a numpy ndarray as a color in OpenCV?


By : Alexander Sadovnikov
Date : March 29 2020, 07:55 AM
wish of those help I am trying to pass a ndarray into this line: cv2.fillPoly(im, pts=[cnt],color=(centroid_color[0],centroid_color[1],centroid_color[2])) , You can pass a numpy array directly as color argument like this:
code :
import numpy as np
import cv2

pts = np.array([[[10,40], [70,16], [100,90] ]], np.int32)
im = np.zeros([240,320, 3], np.uint8)
color = np.array((60,0,255))
cv2.fillPoly( im, pts, color)


cv2.imshow(" ", im)
cv2.waitKey(1)
clr = np.array([255, 0, 128])
cv2.fillPoly( im, pts, color=(clr[0], clr[1], clr[2]))
centroid_color = centroid_color.astype(np.int32, copy=False)
Opencv python HoughLinesP strange results

Opencv python HoughLinesP strange results


By : useryl
Date : March 29 2020, 07:55 AM
this will help NOTE: Since you linked a tutorial for OpenCV 2.4.x, I initially assumed you also wrote your code with OpenCV 2.4.11. As it turns out, you're actually using OpenCV 3.x. Keep in mind that there are subtle changes in the API between 2.x and 3.x.
code :
cv2.HoughLinesP(image, rho, theta, threshold[, lines[, minLineLength[, maxLineGap]]]) → lines
lines = cv2.HoughLinesP(cannied, rho=1, theta=np.pi / 180
    , threshold=80, lines=30, minLineLength=10)
lines = cv2.HoughLinesP(cannied, rho=1, theta=np.pi / 180
    , threshold=80, minLineLength=30, maxLineGap=10)
cv2.Canny(image, threshold1, threshold2[, edges[, apertureSize[, L2gradient]]]) → edges
cannied = cv2.Canny(img, threshold1=50, threshold2=200, edges=3)
cannied = cv2.Canny(img, threshold1=50, threshold2=200, apertureSize=3)
import cv2
import numpy as np


def get_lines(lines_in):
    if cv2.__version__ < '3.0':
        return lines_in[0]
    return [l[0] for l in lines]


img = cv2.imread('building.jpg')
img_gray = gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

cannied = cv2.Canny(img_gray, threshold1=50, threshold2=200, apertureSize=3)
lines = cv2.HoughLinesP(cannied, rho=1, theta=np.pi / 180, threshold=80, minLineLength=30, maxLineGap=10)

for line in get_lines(lines):
    leftx, boty, rightx, topy = line
    cv2.line(img, (leftx, boty), (rightx,topy), (255, 255, 0), 2)

cv2.imwrite('lines.png',img)
cv2.imwrite('canniedHouse.png',cannied)
cv2.waitKey(0)
cv2.destroyAllWindows()
OpenCV BackgroundSubtractor yields poor results on objects with similar color as background color

OpenCV BackgroundSubtractor yields poor results on objects with similar color as background color


By : Daniel Hanley
Date : March 29 2020, 07:55 AM
Any of those help I believe following the steps below will solve your first problem to a large extent:
1.Preprocessing:
Related Posts Related Posts :
  • Dereference FFI pointer in Python to get underlying array
  • Python - Destroying a StaticBoxSizer in wxPython
  • Using Flask to access Google's API
  • Django Form Based on Variable Attributes
  • Relocate all the evens
  • How to scrap span ids' texts in beautifulsoup in the following html?
  • How to generate random number in a given range as a Tensorflow variable
  • Gradient Descent Variation doesn't work
  • Python 2.7 - search for a particular URL on a webpage with ajax
  • How to configure Luigi task retry correctly?
  • web.py : an urlencoded slash into args
  • Use of pyzmq's logging handler in python
  • How to count the number of a particular entry. python
  • devide int into lower whole ints
  • Access atribute of every object in pandas dataframe column
  • Combine Dataframe rows on conditions
  • Select closest date (or value) in pandas / python
  • Pycharm and remote interpreter (Docker) shows errors but runs fine
  • Get started to launch google-cloud-ml with my own dataset
  • Multiprocessing: use only the physical cores?
  • Django Login Custom Auth works locally but not on production server
  • Python: Invalid HTTP basic authentication header with long base64 string
  • How can I request several pages without wating for the output?
  • Flask Response vs Flask make_response
  • python linear regression predict by date
  • How to get pandas dataframe where columns are the subsequent n-elements from another column dataframe?
  • MYSQL: "Access denied for user 'X'@'localhost' (using password: YES)" PYTHON
  • install scipy package via pycharm in windows 10 64 bit - python 3.5
  • Update time in linux and solaris machines from robot framework
  • Complex pandas isin function
  • Averaging over every n elements of an array without numpy
  • An elegant way of inserting multiple arguments
  • IntegrityError:NOT NULL constraint failed: chatapp_chat.message
  • Indexing of 3d numpy arrays with 2d arrays
  • Creating a mean of columns with csv writer
  • Reading in environment variables from an environment file
  • Collapse duplicate rows with pandas
  • How can I use skyfied to convert SGP4 TEME coordinate to ECEF?
  • How to modify object in Python's Rtree index
  • Create Hexbin plot with pandas dataframe using index and columns names as x and y
  • SQLAlchemy query returns no data if a database field is empty
  • Python pandas column asignment between dataframe and series does not work
  • ValueError: Unknown label type: array while using Decision Tree Classifier and using a custom dataset
  • Trouble accessing exif information with PIL.Image._getexif()
  • Use all coordinates in a grid except with certain value
  • Why for loop is splitting strings of user input?
  • How can I add two variable and assign to result variable in Python?
  • Error when parsing timestamp with pandas read_csv
  • Slicing arrays based on boolean array in python
  • Feeding scipy.sparse() sparse matrices into CVXOPT
  • How to separate a irregularly cased string to get the words? - Python
  • Pandas: replace some values in column if that contain a substring
  • Fabric does not close the ssh connection
  • Python Creating Classes Code
  • When will train() method in easy_seq2seq stop?
  • How to split each element of the RDD in spark with python?
  • Read in csv file in python, round the values and write back to file
  • How to properly close a QWidget-window in an API with PythonQt
  • How to know which segment a value reside in
  • pandas: convert multiple categories to dummies
  • shadow
    Privacy Policy - Terms - Contact Us © soohba.com