import cv2 as cv
import numpy as np
#Read images
img=cv.imread(r'E:\Downloaded\pexels\The sea21471.jpeg',1)
#Get the image's aspect information
sp=img.shape
length=sp[1]
heighth=sp[0]
print('width:{},height:{}'.format(length,height)) of the loaded image
#Display window and picture
cv.namedWindow('original image')
cv.imshow('original image',img)
#convert to grayscale image
img2=cv.cvtColor(img,cv.COLOR_BGR2GRAY)
cv.namedWindow('after conversion')
cv.imshow('after conversion',img2)
#image binarization
cv.threshold(img,280,500,0,img)
cv.namedWindow('image binarization')
cv.imshow('image binarization',img2)
# Set the window wait time, 0 means always display
cv.waitKey(0)
#Manual memory release
cv.destroyAllWindows()
After Baidu saw the answer to a similar question, it was because the path was wrong, that is, the picture could not be found, so it reported an error. After modifying the path, the picture was successfully displayed, and the effect was as follows:
Undertake MATLAB, Python and C + + programming, machine learning, computer vision theory implementation and guidance, undergraduate and master can, salted fish trading,
Read More:
- [Solved] size_from_dim: Assertion `dim >= 0 && (size_t)dim < sizes_.size()` failed.
- [Solved] Opencv Error: Error: Assertion failed (data) in cv::Mat::at, file … mat.inl.hpp, line 897(Accessed pixels of non-existent matrix)
- [Solved] Flyter uses screenutil to obtain screen width and height initialization error
- [Solved] OpenCv5 error: (-215:Assertion failed) !_descriptors.empty() in function ‘add‘
- [Solved] RuntimeError: each element in list of batch should be of equal size
- [Solved] Camera Calibration Error: ErrorMessage: Image size does not match the measurement in camera parameters
- [Solved] sqoop Error: jSQLException in nextKeyValue Caused by: ORA-24920:column size too large for client
- [Solved] Canal Error: CanalParseException: column size is not match,parse row data failed
- Tensorflow error: InvalidArgumentError: indices[data_index] = data_value is not in [0, max_embedding_size)
- ValueError: Negative dimension size caused by subtracting 2 from 1 for…
- [Solved] Keil Error: *** ERROR L250: CODE SIZE LIMIT IN RESTRICTED VERSION EXCEEDED
- [HBase Error]“java.lang.OutOfMemoryError: Requested array size exceeds VM limit”
- [Solved] MindSpore Error: “RuntimeError: Invalid data, Page size.”
- [Solved] MindSpore Error: ValueError: Minimum inputs size 0 does not match…
- [Solved] NPM install error: Maximum call stack size exceeded
- [Solved] TFrecords Create Datas Error: Number of int64 values != expected. Values size: 1 but output shape: [3]
- NPM installation error Maximum call stack size exceeded
- error C4996: ‘pcl::SAC_SAMPLE_SIZE‘ [How to Solve]
- [Solved] the request was rejected because its size (11579386) exceeds the configured maximum (10485760)
- Yolox_s.pth Convert to tensorRT Error: AttributeError: ‘tensorrt.tensorrt.Builder‘ object has no attribute ‘max_workspace_size‘