本文整理汇总了Python中SimpleCV.Image.open方法的典型用法代码示例。如果您正苦于以下问题:Python Image.open方法的具体用法?Python Image.open怎么用?Python Image.open使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimpleCV.Image
的用法示例。
在下文中一共展示了Image.open方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getAttributesFromNetwork
# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import open [as 别名]
def getAttributesFromNetwork(self,Network,image):
# The arrays above will hold the attribute information for the Network
ShapeList = []
AngleList = []
FillList = []
SizeList = [] # The scale will be 1-5; with 5 being the biggest
AdditionList = []
print Network.letter
# Open the image path from the Problems (Image Data) folder
image = Image.open(image)
# Convert it to grayscale for easy processing
grayscale = image.convert("L")
# Convert it to black and white to ensure that there aren't any pixels of any
# other color.
blackwhite = grayscale.point(self.filter,"1")
image = blackwhite
image = image.convert("RGB")
width,height = image.size
colorindex = 0
# Translate the image into pictures with various colors
while True:
color = DISTINCT_COLORS[colorindex]
colorindex += 1
blackpixel = None
for x,y,pixel in self.walk(image):
if pixel == (0,0,0):
blackpixel = (x,y)
break
if not blackpixel:
break
neighbors = [blackpixel]
while len(neighbors) > 0:
processing = list(neighbors)
neighbors = []
for x,y in processing:
image.putpixel((x,y),color)
new = [(x-1,y),(x+1,y),(x,y-1),(x,y+1)]
for x,y, in new:
if (x,y) in neighbors:
continue
if x < 0 or x >= width:
continue
if y < 0 or y >= height:
continue
if image.getpixel((x,y)) != (0,0,0):
continue
neighbors.append((x,y))
# We use the count to save each network as a different image
self.count = str(self.count)
# Save the network image
image.save("Project4/ImagesForProcessing/colored"+self.count+".png")
# Open the network image; here, we'll convert it to a bunch of different
# images with different shapes representing the networks
im = Image.open("Project4/ImagesForProcessing/colored"+self.count+".png")
# Separate the images
colors_dict = color_separator(im)
imageCount = 0
# Iterate through the color dictionary for all of the images
for key,value in colors_dict.iteritems():
if key == (255, 255, 255):
imageCount += 1
continue
imageCount = str(imageCount)
# grab the individual image,
# save it,
value.save("Project4/ImagesForProcessing/"+Network.letter+"coloredSmall"+imageCount+".png")
# then read it back with OpenCV for processing
img = cv2.imread("Project4/ImagesForProcessing/"+Network.letter+"coloredSmall"+imageCount+".png")
# Convert it to grayscale; it processes better this way
imgray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
ret,thresh = cv2.threshold(imgray,127,255,0)
# find the contours in the image
contours,hierarchy = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
# iterate through the contours,
#print "Contour Length: ",len(contours)
#if not contours:
#print "No Contours"
for cnt in contours:
if (len(contours)) == 1:
FillList.append("yes")
else:
FillList.append("no")
#print "Looking through contours"
#if (count%2) == 1:
#count = count + 1
#print "Count2: ",count
#continue
# approximate how many sides it has
approx = cv2.approxPolyDP(cnt,0.01*cv2.arcLength(cnt,True),True)
print len(approx)
area = cv2.contourArea(cnt)
if len(approx) == 5:
print "Half-Arrow"
ShapeList.append("Half-Arrow")
if len(approx) == 7:
print "Arrow"
ShapeList.append("Arrow")
elif len(approx) == 3:
print "Triangle"
#.........这里部分代码省略.........
示例2: BytesIO
# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import open [as 别名]
BAD_PACKET = False
IMG_BUFFER = BytesIO()
if NEXT_PACKET != SEQ_NUM:
BAD_PACKET = True
NEXT_PACKET = 0
syslog.syslog(syslog.LOG_DEBUG, "Missed packet sequence number."\
+ "Expected %s, got %s" % (NEXT_PACKET, SEQ_NUM))
if binascii.crc32(PAYLOAD) != CRC_32:
BAD_PACKET = True
syslog.syslog(syslog.LOG_DEBUG, "Bad PAYLOAD CRC in packet")
if BAD_PACKET == False and NEXT_PACKET == SEQ_NUM:
for i in range(0, BYTES_SENT):
IMG_BUFFER.write(list(PAYLOAD)[i])
NEXT_PACKET += 1
if LAST_PKT == True and BAD_PACKET == False:
for proc in psutil.process_iter():
if proc.name == "display":
proc.kill()
NEXT_PACKET = 0
FILE_NAME = str(int(time.time())) + '.jpg'
JPG_FILE = open(FILE_NAME, 'wb')
JPG_FILE.write(IMG_BUFFER.getvalue())
JPG_FILE.close()
Image.open(StringIO(IMG_BUFFER.getvalue())).show()
elif LAST_PKT == True and BAD_PACKET == True:
NEXT_PACKET = 0
BAD_PACKET = False
syslog.syslog(syslog.LOG_ERR,
"Received last packet afer bad packets. Resetting")
>>>>>>> 978c811362e9a2947741249d19bac3a7a378b04a