Tags down


Calculate the white pixel inside cv2.circle

By : vaschops
Date : July 31 2020, 04:00 PM
around this issue I am not sure what you consider as "white", but here is one way to do the counting in Python/OpenCV. Simply read the image. Convert to grayscale. Threshold it at some level. Then just count the number of white pixels in the thresholded image.
If I use your output image for my input (after removing your white border):
code :
import cv2
import numpy as np

# read image
img = cv2.imread('optic.png')

# convert to HSV and extract saturation channel
gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)

# threshold
thresh = cv2.threshold(gray, 175, 255, cv2.THRESH_BINARY)[1]

# count number of white pixels
count = np.sum(np.where(thresh == 255))
print("count =",count)

# write result to disk
cv2.imwrite("optic_thresh.png", thresh)

# display it
cv2.imshow("IMAGE", img)
cv2.imshow("THRESH", thresh)
count = 1025729

Share : facebook icon twitter icon

How do I calculate pixel shader depth to render a circle drawn on a point sprite as a sphere that will intersect with ot

By : Suraj
Date : March 29 2020, 07:55 AM
will be helpful for those in need I came up with a solution yesterday, which which works well and and produces the desired result of a sphere drawn on the sprite, with a correct depth value which intersects with other objects and spheres in the scene. It may be less efficient than it needs to be (it calculates and projects two vertices per sprite, for example) and is probably not fully correct mathematically (it takes shortcuts), but it produces visually good results.
The technique
code :
void SphereVS(float4 vPos // Input vertex,
   float fPointRadius, // Radius of circle / sphere in world coords
   out float fDXScale, // Result of DirectX algorithm to scale the sprite size
   out float fDepth, // Flat sprite depth
   out float4 oPos : POSITION0, // Projected sprite position
   out float fDiameter : PSIZE, // Sprite size in pixels (DX point sprites are sized in px)
   out float fSphereRadiusDepth : TEXCOORDn // Radius of the sphere in depth coords
   // Normal projection
   oPos = mul(vPos, g_mWorldViewProj);

   // DX depth (of the flat billboarded point sprite)
   fDepth = oPos.z / oPos.w;

   // Also scale the sprite size - DX specifies a point sprite's size in pixels.
   // One (old) algorithm is in http://msdn.microsoft.com/en-us/library/windows/desktop/bb147281(v=vs.85).aspx
   fDXScale = ...;
   fDiameter = fDXScale * fPointRadius;

   // Finally, the key: what's the depth coord to use for the thickness of the sphere?
   fSphereRadiusDepth = CalculateSphereDepth(vPos, fPointRadius, fDepth, fDXScale);

float CalculateSphereDepth(float4 vPos, float fPointRadius, float fSphereCenterDepth, float fDXScale) {
   // Calculate sphere depth.  Do this by calculating a point on the
   // far side of the sphere, ie cast a ray from the eye, through the
   // point sprite vertex (the sphere center) and extend it by the radius
   // of the sphere
   // The difference in depths between the sphere center and the sphere
   // edge is then used to write out sphere 'depth' on the sprite.
   float4 vRayDir = vPos - g_vecEyePos;
   float fLength = length(vRayDir);
   vRayDir = normalize(vRayDir);
   fLength = fLength + vPointRadius; // Distance from eye through sphere center to edge of sphere

   float4 oSphereEdgePos = g_vecEyePos + (fLength * vRayDir); // Point on the edge of the sphere
   oSphereEdgePos.w = 1.0;
   oSphereEdgePos = mul(oSphereEdgePos, g_mWorldViewProj); // Project it

   // DX depth calculation of the projected sphere-edge point
   const float fSphereEdgeDepth = oSphereEdgePos.z / oSphereEdgePos.w;
   float fSphereRadiusDepth = fSphereCenterDepth - fSphereEdgeDepth; // Difference between center and edge of sphere
   fSphereRadiusDepth *= fDXScale; // Account for sphere scaling

   return fSphereRadiusDepth;
void SpherePS(
    float fSpriteDepth : TEXCOORD0,
    float fSphereRadiusDepth : TEXCOORD1,
    out float4 oFragment : COLOR0,
    out float fSphereDepth : DEPTH0
   float fCircleDist = ...; // See example code in the question
   // 0-1 value from the center of the sprite, use clip to form the sprite into a circle

   fSphereDepth = fSpriteDepth + (fCircleDist * fSphereRadiusDepth);

   // And calculate a pixel color
   oFragment = ...; // Add lighting etc here

Get all pixel array inside circle

By : mmd378
Date : March 29 2020, 07:55 AM
should help you out I have this: , You are looking for the following set of pixels:
code :
List<int> indices = new List<int>();

for (int x = 0; x < width; x++)
    for (int y = 0; y < height; y++)
        double dx = x - m1;
        double dy = y - m2;
        double distanceSquared = dx * dx + dy * dy;

        if (distanceSquared <= radiusSquared)
            indices.Add(x + y * width);

running on every pixel inside a circle

By : user3029831
Date : March 29 2020, 07:55 AM
this will help You need to create an imaginary grid, or rather a grid that is only useful in that it will help you solve the problem at hand. This is the grid that you will assign all the bitmaps to a position on, imagining that the circle's center is to be located at (0,0).
You then use a little math

calculate pixel coordinates for 8 equidistant points on a circle

By : Karlo Huerta Kayser
Date : March 29 2020, 07:55 AM
help you fix your problem I have a circle centred at 0 with radius 80. How using python do I calculate the coordinates for 8 equidistant points around the circumference of the circle?
code :
r = 80
numPoints = 8.0
points = []
for index in range(numPoints):
return points
r = 80
numPoints = 8
points = []
x = (r*math.sqrt(2))/2
points = [[0,r],[x,x],[r,0],[-x,x],[-r,0],[-x,-x],[0,-r],[x,-x]]
print points

How to create a white border circle having white exclamation mark inside a box having a yellow background in html/css?

By : garik
Date : March 29 2020, 07:55 AM
like below fixes the issue No need to use an image here, it's easier, faster, more scalable and flexible to use a pseudo element like ::before here:
code :
.my-paragraph-style {
  background: #EABB27;
  padding: 20px 20px 20px 50px;
  line-height: 1.4;
  position: relative;
  font-family: arial, helvetica, sans-serif;
  color: white;
  font-weight: bold;
  font-size: 14px;
  max-width: 300px;
.my-paragraph-style::before {
  display: block;
  position: absolute;
  left: 20px;
  top: 23px;
  content: "!";
  border-radius: 50%;
  border: 1px solid yellow;
  width: 20px;
  height: 20px;
  line-height: 22px;
  text-align: center;
  color: yellow;
  font-weight: normal;
<p class="my-paragraph-style">List your dependents and enter their personal information. Pay close attention to information regarding your spouse’s smoking habits.</p>
Related Posts Related Posts :
  • How to store many inputs from a user in a set
  • concise way to unpack twice from returned
  • Reshaping the Row into Columns of dataframe
  • Provide stdin input from file in cmd?
  • Fast method of applying sine to a matrix
  • Concatenating two multi dimensional arrays
  • Replace some values with a string in a column in python
  • pyspark: when printing my dataframe, why don't I see the actual values? I just get DataFrame[avg(Rate): double]
  • transforming R function output to match format of Python function output
  • Summing particular rows in a particular column
  • Get source code of calling function in python
  • Use latest version of Python as default
  • Remove element from a Python list until found a specific character
  • Don't understand why I'm getting a NameError for a variable
  • How can I print a statement only if an equation is not satisfied?
  • How do I change the value type of a particular key in a dictionary in a list?
  • Python "SyntaxError: invalid syntax" why?
  • Creating a Conditional Function in Python
  • Tkinter, remove redundant rows if values removed from CSV file
  • Meaning of an empty line in Python source code file
  • how to use seperator in python when string multiplied by integer
  • Expected ETA to avail Pipeline I/O and runtime parameters in apache beam GCP dataflow pipeline using python?
  • psycopg2 process cursor results with muliple threads or processes
  • How to identify data rows for the last 10 days in CSV file with pandas?
  • How to remove commas from only few elements in a list
  • Is there a way to assign variable in Robot Framework to python without using it as an argument?
  • Multiplication between arrays of different shape in numpy
  • Rearrange dictionary so that value is the next key
  • can't access image url from template, python django
  • Random values of rows with minimum unique values of a column pandas
  • how to check whether a certain number is in the Pytorch tensor?
  • Shorten without using break
  • How can we replace NaNs in only specific rows?
  • If __name__ == "__main__":
  • Python - Filtering Extremely Large XML File
  • Can this comparator function be replaced with an equivalent key function?
  • Python - Wildcards for integer values?
  • How to convert a list into object with multiple parameters
  • What does a "TypeError: 'int' object is not callable" mean?
  • Pandas- Concatenating two columns of string lists
  • How to clip the real and imaginary parts of elements of a python numpy array of complex numbers
  • How to compare string time in python
  • How do I find "n" maximum values for each month in a pandas dataframe?
  • Replacing a string inside of a list with another string
  • Print DataFrame as comma separated values
  • How to print all possible combinations in string using itertools?
  • Appending to a recursive list in python
  • Assign cumulative values for flag for consecutive values in Pandas dataframe
  • Read CSV file with limit and offset
  • Machine Learning - How to predict set of fixed fields based on past features
  • How to keep text formatting in HTML Input Form?
  • ValueError: could not convert string to float: '31,950'
  • Why does `asyncio.run()` never return in Python 3.8?
  • Accessing nth element from tuples in list, but the length of the tuple is different
  • Use subprocess to open an exe file and interact with it
  • Python: how to merge two dataframes and count over the days?
  • Extract horizontal and vertical lines from an image
  • Is it possible to implement this version of matrix multiplication using Numpy?
  • my picture won't resize tf.image.resize_with_padding tensorflow
  • Why isn't my Django object saved to the database?
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org