import cv2 img = cv2.imread('libarary.JPG', 1)dst = img[350:650,550:800] #这里选取矩形区域X:550-800 Y:350-650#cv2.imshow('image',dst) #cv2.waitKey(0)
以下会在jupyterLab控件中显示两种压缩后的图像对比显示
#bgr8转jpeg格式 import enum import cv2def bgr8_to_jpeg(value, quality=75):return bytes(cv2.imencode('.jpg', value)[1])
import ipywidgets.widgets as widgetsimage_widget1 = widgets.Image(format='jpg', ) image_widget2 = widgets.Image(format='jpg', )# display the container in this cell's output display(image_widget1) display(image_widget2)img1 = cv2.imread('libarary.JPG',1)image_widget1.value = bgr8_to_jpeg(img1) #原始图像 image_widget2.value = bgr8_to_jpeg(dst) #剪切的图像