当前位置: 首页>>代码示例>>Python>>正文


Python Image.crop方法代码示例

本文整理汇总了Python中SimpleCV.Image.crop方法的典型用法代码示例。如果您正苦于以下问题:Python Image.crop方法的具体用法?Python Image.crop怎么用?Python Image.crop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SimpleCV.Image的用法示例。


在下文中一共展示了Image.crop方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: capture

# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import crop [as 别名]
    def capture(self):
        count = 0
        currentframes = []
        self.framecount = self.framecount + 1

        for c in self.cameras:
            img = ""
            if c.__class__.__name__ == "Kinect" and c._usedepth == 1: 
                img = c.getDepth()
            elif c.__class__.__name__ == "Kinect" and c._usematrix == 1:
                mat = c.getDepthMatrix().transpose()
                img = Image(np.clip(mat - np.min(mat), 0, 255))
            else:
                img = c.getImage()
            if self.config.cameras[0].has_key('crop'):
                img = img.crop(*self.config.cameras[0]['crop'])
            frame = M.Frame(capturetime = datetime.utcnow(), 
                camera= self.config.cameras[count]['name'])
            frame.image = img
            currentframes.append(frame)
            
            while len(self.lastframes) > self.config.max_frames:
                self.lastframes.pop(0)
            # log.info('framecount is %s', len(self.lastframes))
                            
#            Session().redis.set("framecount", self.framecount)
            count = count + 1
            
                    
        self.lastframes.append(currentframes)            
            
        return currentframes
开发者ID:ravikg,项目名称:SimpleSeer,代码行数:34,代码来源:SimpleSeer.py

示例2: crop

# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import crop [as 别名]
def crop():
    #Begin Processing image
    print ('Begin processing image...')
    fullImage = Image('test/image/expected/fullImage.jpg')
    hundreds = fullImage.crop(602, 239, 28, 63)
    hundreds = hundreds.binarize(65).invert()
    hundreds.save('test/image/actual/hundredsImage.jpg')
    print ('Hundreds place cropped, binarized, and saved')
开发者ID:nthrockmorton,项目名称:wmr,代码行数:10,代码来源:wmr.py

示例3: blob

# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import crop [as 别名]
def blob(id):
    cur = g.db.execute("SELECT id, image, x, y, width, height FROM annotations WHERE annotations.id=?", [id])
    line = cur.fetchone()

    img = Image("static\\img\\%d.jpg" % int(line[1]))
    blob = img.crop(line[2], line[3], line[4], line[5])
    io = StringIO()
    blob.save(io)
    data = io.getvalue()
    resp = make_response(data)
    resp.content_type = "image/jpeg"
    return resp
开发者ID:rolisz,项目名称:image_annotator,代码行数:14,代码来源:flask_annotator.py

示例4: getImage

# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import crop [as 别名]
 def getImage(self):
     if isinstance(self._scv_cam, Kinect):
         if self._scv_cam._usedepth == 1:
             img = self._scv_cam.getDepth()
         elif self._scv_cam._usematrix == 1:
             mat = self._scv_cam.getDepthMatrix().transpose()
             img = Image(np.clip(mat - np.min(mat), 0, 255))
         else:
             img = self._scv_cam.getImage()
     else:
         img = self._scv_cam.getImage()
     if self.crop:
         img = img.crop(self.crop)
     return img
开发者ID:ravikg,项目名称:SimpleSeer,代码行数:16,代码来源:camera.py

示例5: capture_camera_image

# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import crop [as 别名]
def capture_camera_image():
    log("capture_camera_image()")
    image = None
    if USE_MOTION_CAMERA:
        image = Image(MOTION_CAMERA_SNAPSHOT)
    else:  # default to USE_WEB_CAMERA
        if cam is None:
            image = Camera().getImage()
        else:
            image = cam.getImage()

    size = image.size()

    # dynamic background mean color calculation
    if (BACKGROUND_AUTO_CALIBRATE):
        x = CROP_IMAGE_BORDERS[0]
        y = CROP_IMAGE_BORDERS[1]
        if (x > 0 and y > 0):
            background = image.crop(0, 0, x, y)
            mean_color = background.meanColor()
            log("background as (%d, %d, %d)" % (mean_color[0], mean_color[1], mean_color[2]))
            # save it
            db = db_open()
            db_backgrounds_write(db, db_background(date_created=datetime.now(), mean_color=mean_color))
            db_close(db)

    # if image border needs to be cropped
    x = CROP_IMAGE_BORDERS[0]
    y = CROP_IMAGE_BORDERS[1]
    if (x > 0 and y > 0):
        width = size[0] - 2 * x
        height = size[1] - 2 * y
        cropped = image.crop(x, y, width, height)
    else:
        cropped = image
    return cropped
开发者ID:jonahgroup,项目名称:SnackWatcher,代码行数:38,代码来源:utils.py

示例6: line_blobs

# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import crop [as 别名]
def line_blobs(id):
    cur = g.db.execute("SELECT id, x, y, width, height FROM blobs WHERE image=?", [id])
    blobs = cur.fetchall()
    entries = []
    img = Image("static\\img\\%d.jpg" % id)
    for i, entry in enumerate(blobs):
        blob = img.crop(entry[1], entry[2], entry[3], entry[4])
        if blob and "SK_MODEL" in app.config:
            if blob.height > blob.width:
                blob = blob.resize(h=app.config["PATCH_SIZE"])
            else:
                blob = blob.resize(w=app.config["PATCH_SIZE"])
            blob = blob.embiggen((app.config["PATCH_SIZE"], app.config["PATCH_SIZE"]))
            np_img = blob.getGrayNumpy().transpose().reshape(-1)
            pred = labels.inverse_transform(sk_model.predict(np_img))[0]
            if app.config["DEBUG"]:
                blob.save("tmp\\pic%d %s.jpg" % (i, pred))
            entries.append(dict(x=entry[1], y=entry[2], width=entry[3], height=entry[4], pred=pred))
        else:
            entries.append(dict(x=entry[1], y=entry[2], width=entry[3], height=entry[4]))
    return jsonify(blobs=entries)
开发者ID:rolisz,项目名称:image_annotator,代码行数:23,代码来源:flask_annotator.py

示例7: get_faces

# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import crop [as 别名]
def get_faces(image_path, api_mode=False, rescale_face_crop=0):
    """
    Return a list of cropped faces given an image path

    :param image_path: Path to image
    :type image_path: str
    :param api_mode: If api_mode is True get_faces returns a list of found HaarFeatures
    :type api_mode: bool
    :returns: list of images
    """

    original_image = Image(image_path)
    faces = original_image.findHaarFeatures(segment_face)

    if api_mode:
        return faces
    else:
        if rescale_face_crop:
            return [original_image.crop(scale_bounding_box(face.boundingBox(), rescale_face_crop)) for face in faces]
        else:
            return [face.crop() for face in faces]
开发者ID:dnmellen,项目名称:facehugger,代码行数:23,代码来源:facehugger.py

示例8: generate_negative_examples

# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import crop [as 别名]
def generate_negative_examples(argv):
    image_dirs = argv[4:]

    images = []
    for image_dir in image_dirs:
        # grab all images
        images.extend(glob(path.join(image_dir, '*.jpg')))
        images.extend(glob(path.join(image_dir, '*.JPG')))
        images.extend(glob(path.join(image_dir, '*.png')))
        images.extend(glob(path.join(image_dir, '*.PNG')))

    images = set(images)

    if len(images) < N:
        print 'Not enough images! (got %d, need %d)' % (len(images), N)
        return

    width, height, output_dir = int(argv[1]), int(argv[2]), argv[3]

    if path.exists(output_dir) and (not path.isdir(output_dir)):
        print '%s is not a directory' % output_dir
        return
    elif not path.exists(output_dir):
        os.mkdir(output_dir)

    for i in xrange(N):
        print 'generating %3d/%d...' % ((i+1), N)
        img = Image(images.pop())
        img = img.grayscale()
        if img.width > MAX_WIDTH:
            img = img.resize(MAX_WIDTH, int(1.0*img.height*MAX_WIDTH/img.width))

        x, y = random.randint(0, img.width-width), random.randint(0, img.height-height)
        img = img.crop(x, y, width, height)

        path_to_save = path.join(output_dir, '%d.png' % (i+1))
        img.save(path_to_save)
开发者ID:kavinyao,项目名称:airplane-recognition,代码行数:39,代码来源:generate_negative.py

示例9: Image

# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import crop [as 别名]
from SimpleCV import Image,Color
car_in_lot = Image("parking-car.png")
car_not_in_lot = Image("parking-no-car.png")
car = car_in_lot.crop(470,200,200,200)
yellow_car = car.colorDistance(Color.YELLOW)

yellow_car.show()
开发者ID:srinath9,项目名称:simplecv,代码行数:9,代码来源:shading.py

示例10: VirtualCamera

# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import crop [as 别名]
from __future__ import print_function
from SimpleCV import Image, Color, VirtualCamera, Display
import SimpleCV as scv

# # video = VirtualCamera('', 'video')
# display = Display()

# while display.isNotDone():
# 	img = video.getImage()
# 	try:
# 		dist = img - img.colorDistance(Color.RED)
# 		dist.show()
# 	except KeyboardInterrupt:
# 		display.done = True
# 	if display.mouseRight:
# 		display.done = True
# display.quit()

img = Image('img/curb.JPG')
img = img.crop(0, 2*img.height/3, img.width, 5*img.height/6)
print(img.meanColor())
# img = img.binarize()
# img.findBlobs().draw()
# ls = img.findLines()
# for l in ls:
	# l.draw()
# img.findBlobs().draw()
# img = img.colorDistance(Color.RED)

img.save('img/curb_processed.jpg')
开发者ID:ajayjain,项目名称:OpenCV-Projects,代码行数:32,代码来源:curbside.py

示例11: histo

# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import crop [as 别名]
    def histo(self):
        cam_mode = self.cam_mode
        js = self.js
        ms = self.ms
        w = self.w
        cent = 0
        rgb1 = 0
        c2 = self.c2
        wsh = self.wsh 
        wsh2 = self.wsh2
        s.write('s')
        
        if cam_mode == 3:
            img1 = c2.getImage()
        if cam_mode==1:
            with picamera.PiCamera() as camera:
                camera.resolution = (544, 288)
                camera.capture('imagesmall.jpg')
            img1 = Image('imagesmall.jpg')
        if cam_mode==2:
            with picamera.PiCamera() as camera:
                camera.resolution = (544, 288)
                camera.capture('imagesmall.jpg')
            img1 = Image('imagesmall.jpg')
        self.img1 = img1
        blobs = img1.findBlobs()  
        
        if blobs:
            print "blob"
            x = self.x
            y = self.y
            p = self.p
            p = p + 1
            img1.drawCircle((blobs[-1].x,blobs[-1].y),30,color=(255,255,255))
            img1.drawCircle((blobs[0].centroid()),10,color=(255,100,100))
            print blobs[-1].meanColor()
            rgb1 = blobs[-1].meanColor()
            cent = blobs[-1].centroid()

            pth1 = "/var/www/images/image"
            pth3 = ".png"
            pth = pth1 + str(p) + pth3
            print pth
            img1.save(pth)
            
            thumbnail = img1.crop(150,25,250,250)
            thumbnail = thumbnail.scale(20,20)
            thumb1 = "/var/www/images/thumbs/thumb"
            thumb3 = ".png"
            thumbpath = thumb1 + str(p) + thumb3
            print thumbpath
            thumbnail.save(thumbpath)
            
            self.p = p
            
            mySet.add((p,x,y,w,cent,rgb1))
            self.mySet = mySet
            
            wshx = str(self.x)
            wshy = str(self.y)
            centroidx = int(cent[0])
            centroidy=int(cent[1])
            rcolor=rgb1[0]
            gcolor=rgb1[1]
            bcolor=rgb1[2]
            rcolor=int(rcolor)
            gcolor=int(gcolor)
            bcolor=int(bcolor)
            wsh.write_message(wsh2, "rgb_" + str(rcolor)+"_"+str(gcolor)+"_"+str(bcolor))
            wsh.write_message(wsh2, "x_" + str(centroidx)+"_"+str(centroidy))
            img1.save(js.framebuffer)
            wsh.write_message(wsh2, "d_" + wshx + "_" + wshy + "_" + str(p) )

        else:
            wshx = str(self.x)
            wshy = str(self.y)
            wsh.write_message(wsh2, wshx + " " + wshy + "dark")
 
            print "dark"
开发者ID:juoni,项目名称:ogp,代码行数:81,代码来源:ogplab.py

示例12: Image

# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import crop [as 别名]
from SimpleCV import Image
import time
img = Image('ladies.jpg')
# Crop starting at +(50, 5)+ for an area 280 pixels wide by 500 pixels tall
cropImg = img.crop(80, 5, 280, 500)
cropImg.show()
time.sleep(10)
开发者ID:popsonebz,项目名称:lesson1,代码行数:9,代码来源:helloWorld17.py

示例13: Image

# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import crop [as 别名]
from SimpleCV import Image
img = Image('ahmedabad.jpg')

cropImg = img.crop(50, 5, 200, 200)
cropImg.show()
raw_input()

开发者ID:SamarthShah,项目名称:SciPy.In-2013,代码行数:8,代码来源:3-Image+Crop.py

示例14: Image

# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import crop [as 别名]
from __future__ import print_function
from SimpleCV import Image, Color

im = Image("img/ardrone.jpg")
# im = im.erode()
im = im.crop(2000, 1500, 2000, 2000, centered=True)
# im = im.erode()
# blobs = im.findBlobs()
# blobs.draw()

only_orange = im - im.colorDistance(Color.ORANGE)
only_black 	= im - im.colorDistance(Color.BLACK)
only_drone  = only_orange + only_black


body.save("img/ardrone2.jpg")
# raw_input("Hit enter to quit: ")
# window.quit()
开发者ID:ajayjain,项目名称:OpenCV-Projects,代码行数:20,代码来源:ar_drone.py

示例15: Image

# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import crop [as 别名]
from SimpleCV import Image, Color, Display
import argparse

parser = argparse.ArgumentParser(description='Check for car in handicap spot.')
parser.add_argument('img')
args = parser.parse_args()
img = args.img

image = Image(img)

cropped_image = image.crop(470,200,200,200)

color_distance = cropped_image.colorDistance(Color.YELLOW)

spot = cropped_image - color_distance
spot = spot.toRGB()

(r, g, b) =spot.meanColor()

if ((r>15) and (g>10)):
    print "The car is in the lot. Call the attendant."
else:
    print "The car is not in the lot."
开发者ID:vizcacha,项目名称:practicalcv,代码行数:25,代码来源:check_for_car.py


注:本文中的SimpleCV.Image.crop方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。