我写了一个更新函数,但是多次执行会报错context deadline exceeded。
我的功能:
func Update(link string, m bson.M) {
configInfo := config.Config()
// client := GetInstance().client
// ctx := GetInstance().ctx
client, _ := mongo.NewClient(options.Client().ApplyURI("mongodb://localhost:27017"))
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
err := client.Connect(ctx)
if err != nil {
fmt.Print("connect error!")
fmt.Println(err)
}
db := client.Database("test")
lianjia := db.Collection("test")
_, err = lianjia.UpdateOne(ctx, bson.M{"Link": link}, bson.M{"$set": m})
if err != nil {
fmt.Print("update error!")
fmt.Println(err)
}
}
Run Code Online (Sandbox Code Playgroud)
输出:
update error!context deadline exceeded
Run Code Online (Sandbox Code Playgroud) import cv2
def clear(img):
back = cv2.imread("back.png", cv2.IMREAD_GRAYSCALE)
img = cv2.bitwise_xor(img, back)
ret, img = cv2.threshold(img, 120, 255, cv2.THRESH_BINARY_INV)
return img
def threshold(img):
ret, img = cv2.threshold(img, 120, 255, cv2.THRESH_BINARY_INV)
img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
ret, img = cv2.threshold(img, 248, 255, cv2.THRESH_BINARY)
return img
def fomatImage(img):
img = threshold(img)
img = clear(img)
return img
img = fomatImage(cv2.imread("1566135246468.png",cv2.IMREAD_COLOR))
cv2.imwrite("aa.png",img)
Run Code Online (Sandbox Code Playgroud)
这是我的代码。但是当我尝试用 tesseract-ocr 识别它时,我收到了警告。
Warning: Invalid resolution 0 dpi. Using 70 instead.
我应该如何设置dpi?
我有[] * Cookie数组,但是如何获取[] Cookie数组?我尝试使用*符号,但是出现语法错误。
public static void test(int x, int y) {
Thread thread = new Thread() {
@Override
public void run() {
System.out.println(x);
}
};
thread.start();
}
Run Code Online (Sandbox Code Playgroud)
这是我的代码。我无法获得x的值。如何在函数的匿名类的方法中获取参数x的值?