mercredi 15 avril 2015

Python create image with continous input

I have a code where an image got converted to B/W. Now I want to build a new image in reference to the original image.


The output of the original image are the X-/Y-coordinates and "1" and "0" for Black and White.


The new image will receive these information but not chronologically. Therefore it must check and provide a negative output if it already has received information about a specific coordinate so that double entries can be avoided.


I haven´t found many similar examples to this; only some examples that are going in the about direction.


Does anyone have an idea how to realize that?


UPDATE:


I built the code which converts a pixel from a white image black, if the reference pixel from the original image is black (Otherwise it leaves it white).


Furthermore the used coordinate is entered into a list and checked if used. However, this part is not working properly. Although the coordinate [10, 10] has been used in the loop before, the code displays Coordinate not in the system


Any help would be appreciated!



import cv2
import numpy

white = cv2.imread('white.jpg') #loading white image
white = cv2.resize(white,(640,480)) #adjusting it to the size of the original image


y = 0 #for testing purposes the white image gets blackened manually
x = 0
j = 0

while j < 50:
content = numpy.zeros((200, 2)) #creating a list with 200 entries, every entry contains 2 values
content = ([x, y]) #adding two values to the list

if condition[y, x] = 1: #condition = 1 means that in the reference picture at this coordinate the pixel is black
white[y,x] = 0 #"0" creates a black pixel at the specified coordinate on the white image
x += 5
y += 5
j += 1

x = 10 #taking a value which already has been used
y = 10

try:
b = content.index([x, y]) #check if coordinate is in the list
except ValueError:
print("Coordinate not in the system")
else:
print("Coordinate already in the system")


i = 0

while i < 100:

cv2.imshow('Bild', white) #displays the image
if cv2. waitKey(1) == ord('q'):
break

Aucun commentaire:

Enregistrer un commentaire