Konvertieren von Kontur -Pixel -Koordinaten in Python OpenCV -Serie mit gepaarten Datum und Dollar -SeriePython

Python-Programme
Anonymous
 Konvertieren von Kontur -Pixel -Koordinaten in Python OpenCV -Serie mit gepaarten Datum und Dollar -Serie

Post by Anonymous »

Problem: Schreiben Sie eine Python -Funktion, die ein Bild (.png -Datei) eingibt, um ihren Inhalt zu analysieren, um Pixel -Koordinateninformationen zu erhalten, bevor die Pixelkoordinaten in Datum und Dollarwerte in einem Array konvertiert werden. Wie beziehe ich das X-Pixel-Koordinatenelement mit der Zeitskala auf der X-Achse des Bildes und dem Y-Pixel-Koordinatenelement des Bildes mit dem Kostenwert der Y-Achse des Bildes? Ich weiß nicht, wie man den $/Pixel -Conversion -Faktor automatisch generiert. Letztendlich versuche ich in Excel, das Bild (.png) in Excel neu zu erstellen, sobald ich die X- und Y-Pixel-Koordinateninformationen in Zeit- und Kostenwerten in einer Reihe konvertiert habe. Bitte verwenden Sie die .png Ich habe diesen Beitrag hochgeladen, um ihn über meinen Code auszuführen, um zu sehen, wo ich im Entwicklungsprozess festgefahren bin.

Code: Select all

import cv2 as vision
import numpy as np

extracted_image = r"filepath..." # as .png

# load the cumulative spend plan image
image = vision.imread(extracted_image)

if image is None:
print("Error: could not load image. Check file path.")
exit()

# convert to HSV color space
hsv_image = vision.cvtColor(image, vision.COLOR_BGR2HSV)
lower_bound = np.array([0,0,0])
upper_bound = np.array([50,50,50])
mask = vision.inRange(hsv_image, lower_bound, upper_bound)

# find contours
contours, _ = vision.findContours(mask, vision.RETR_EXTERNAL, vision.CHAIN_APPROX_SIMPLE)

# intialize
black_contour = None

if contours:
black_contour = max(contours, key=vision.contourArea) # use the largest contour if multiple found

# visualize whether contour was found
if black_contour is not None:
# draw on top of black contour
vision.drawContours(image, [black_contour], -1, (0,0,255), 2)

# get the coordinates of the black contur points
coordinates = black_contour[:,0,:] # get x,y coordinates
print("Coordinates of black contour in pixels:")
for (x,y) in coordinates:
print(f"({x}, {y})")
else:
print("Non black contour found.")

vision.imshow("Cumulative Spend Plan", image)
vision.waitKey(0)
vision.destroyAllWindows()

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post