午夜无码人妻aⅴ大片色欲张津瑜,国产69久久久欧美黑人A片,色妺妺视频网,久久久久国产综合AV天堂

python下載圖片函數(shù) python批量下載圖片代碼

請教如何用python下載文件到本地

知道文件的url地址就用urllib模塊的urlretrieve函數(shù)。urllib.urlretrieve(url,

創(chuàng)新互聯(lián)專注于企業(yè)成都全網(wǎng)營銷、網(wǎng)站重做改版、永德網(wǎng)站定制設(shè)計(jì)、自適應(yīng)品牌網(wǎng)站建設(shè)、html5、商城系統(tǒng)網(wǎng)站開發(fā)、集團(tuán)公司官網(wǎng)建設(shè)、成都外貿(mào)網(wǎng)站建設(shè)公司、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁設(shè)計(jì)等建站業(yè)務(wù),價(jià)格優(yōu)惠性價(jià)比高,為永德等各大城市提供網(wǎng)站開發(fā)制作服務(wù)。

filename)filename是要保存到本地的文件名。函數(shù)后面還有2個(gè)可選參數(shù),要用就看幫助文檔吧。多線下載的話,每一線程要指定下載服務(wù)器上文件的哪一塊。http協(xié)議中head里可以指定Range。下面用的是urllib2模塊request

=

urllib2.Request(url)request.add_header("Range",

"bytes=%d-%d"%(1024,

204)

#指定下載文件的范圍opener

=

urllib2.build_opener()data

=

opener.open(request).read()現(xiàn)在data里面就是文件的1024字節(jié)到2048字節(jié)的內(nèi)容。

python爬蟲大神幫忙看一下啊,使用 urllib.urlretrieve()下載不到圖片,具體圖片看下圖代碼

更改一下地址啊,因?yàn)槟阋螺d的是圖片,所以要用圖片后綴,改成:

work_path?=?"E:/"?+?str(imgname)?+?".jpg"

urllib.request.urlretrieve(imgurl,?work_path)

這個(gè)imgname你定義一個(gè)循環(huán)的名字即可

有大神知道怎么使用python 往ftp服務(wù)器上連續(xù)上傳下載多張圖片嗎?

例:下載、上傳文件

#?coding:?utf-8

from?ftplib?import?FTP

import?time

import?tarfile

import?os

#?!/usr/bin/python

#?-*-?coding:?utf-8?-*-

from?ftplib?import?FTP

def?ftpconnect(host,?username,?password):

ftp?=?FTP()

#?

(host,?21)

(username,?password)

return?ftp

#從ftp下載文件

def?downloadfile(ftp,?remotepath,?localpath):

bufsize?=?1024

fp?=?open(localpath,?'wb')

('RETR?'?+?remotepath,?fp.write,?bufsize)

fp.close()

#從本地上傳文件到ftp

def?uploadfile(ftp,?remotepath,?localpath):

bufsize?=?1024

fp?=?open(localpath,?'rb')

('STOR?'?+?remotepath,?fp,?bufsize)

fp.close()

if?__name__?==?"__main__":

ftp?=?ftpconnect("113.105.139.xxx",?"ftp***",?"Guest***")

downloadfile(ftp,?"Faint.mp4",?"C:/Users/Administrator/Desktop/test.mp4")

#調(diào)用本地播放器播放下載的視頻

os.system('start?"C:\Program?Files\Windows?Media?Player\wmplayer.exe"?"C:/Users/Administrator/Desktop/test.mp4"')

uploadfile(ftp,?"C:/Users/Administrator/Desktop/test.mp4",?"test.mp4")

python讀取保存多幀圖片數(shù)量少了

cv2.imshow("left", img_left)

filename3=str(number)+'n3'+'.jpg' #打印第number張圖片+增值方式+保存類型

cv2.imwrite(savedpath + filename3, img_left)

"""

# 數(shù)據(jù)增強(qiáng)實(shí)現(xiàn)

"""

import cv2

import numpy as np

import os

# 圖像平移

def img_translation(image):

# 圖像平移 下、上、右、左平移

M = np.float32([[1, 0, 0], [0, 1, 100]])

img_down = cv2.warpAffine(image, M, (image.shape[1], image.shape[0]))

M = np.float32([[1, 0, 0], [0, 1, -100]])

img_up = cv2.warpAffine(image, M, (image.shape[1], image.shape[0]))

M = np.float32([[1, 0, 100], [0, 1, 0]])

img_right = cv2.warpAffine(image, M, (image.shape[1], image.shape[0]))

M = np.float32([[1, 0, -100], [0, 1, 0]])

img_left = cv2.warpAffine(image, M, (image.shape[1], image.shape[0]))

# 保存圖片,需要保存上述的哪一圖片,就在cv2.imwrite()中,將哪一圖片名放入。

# filename='xxx' +'.jpeg'

# cv2.imwrite(savedpath + filename, img_left)

# 顯示圖形

cv2.imshow("down", img_down)

filename0=str(number)+'n0'+'.jpg'

cv2.imwrite(savedpath + filename0, img_down)

cv2.imshow("up", img_up)

filename1=str(number)+'n1'+'.jpg'

cv2.imwrite(savedpath + filename1, img_up)

cv2.imshow("right", img_right)

filename2=str(number)+'n2'+'.jpg'

cv2.imwrite(savedpath + filename2, img_right)

cv2.imshow("left", img_left)

filename3=str(number)+'n3'+'.jpg'

cv2.imwrite(savedpath + filename3, img_left)

# 圖像縮放

def img_scale(image):

result = cv2.resize(image, (224, 224))

cv2.imshow("scale", result)

filename=str(number)+'n5'+'.jpg'

cv2.imwrite(savedpath + filename, result)

# 圖像翻轉(zhuǎn)

def img_flip(image):

# 0以X軸為對稱軸翻轉(zhuǎn),0以Y軸為對稱軸翻轉(zhuǎn), 0X軸Y軸翻轉(zhuǎn)

horizontally = cv2.flip(image, 0) # 水平鏡像

vertically = cv2.flip(image, 1) # 垂直鏡像

hv = cv2.flip(image, -1) # 水平垂直鏡像

# 顯示圖形

cv2.imshow("Horizontally", horizontally)

filename1=str(number)+'n6'+'.jpg'

cv2.imwrite(savedpath + filename1, horizontally)

cv2.imshow("Vertically", vertically)

filename2=str(number)+'n7'+'.jpg'

cv2.imwrite(savedpath + filename2, vertically)

cv2.imshow("Horizontally Vertically", hv)

filename3=str(number)+'n8'+'.jpg'

cv2.imwrite(savedpath + filename3, hv)

# 圖像旋轉(zhuǎn)

def img_rotation(image):

# 原圖的高、寬 以及通道數(shù)

rows, cols, channel = image.shape

# 繞圖像的中心旋轉(zhuǎn)

# 參數(shù):旋轉(zhuǎn)中心 旋轉(zhuǎn)度數(shù) scale

M = cv2.getRotationMatrix2D((cols / 2, rows / 2), 30, 1)

# 參數(shù):原始圖像 旋轉(zhuǎn)參數(shù) 元素圖像寬高

rotated = cv2.warpAffine(image, M, (cols, rows))

# 顯示圖像

cv2.imshow("rotated", rotated)

filename1=str(number)+'n9'+'.jpg'

cv2.imwrite(savedpath + filename1, rotated)

#選裝60度

W = cv2.getRotationMatrix2D((cols / 2, rows / 2), 60, 1)

# 參數(shù):原始圖像 旋轉(zhuǎn)參數(shù) 元素圖像寬高

rotated1 = cv2.warpAffine(image, W, (cols, rows))

cv2.imshow("rotated", rotated)

filename2=str(number)+'n12'+'.jpg'

cv2.imwrite(savedpath + filename2, rotated1)

#選裝145度

W = cv2.getRotationMatrix2D((cols / 2, rows / 2), 60, 1)

# 參數(shù):原始圖像 旋轉(zhuǎn)參數(shù) 元素圖像寬高

rotated2 = cv2.warpAffine(image, W, (cols, rows))

cv2.imshow("rotated", rotated)

filename3=str(number)+'n13'+'.jpg'

cv2.imwrite(savedpath + filename3, rotated2)

# 圖像加噪

def img_noise(image, mean=0, var=0.001):

'''

添加高斯噪聲

mean : 均值

var : 方差

'''

image = np.array(image / 255, dtype=float)

noise = np.random.normal(mean, var ** 0.5, image.shape)

out = image + noise

if out.min() 0:

low_clip = -1.

else:

low_clip = 0.

out = np.clip(out, low_clip, 1.0)

out = np.uint8(out * 255)

cv2.imshow("noise", out)

filename3=str(number)+'n10'+'.jpg'

cv2.imwrite(savedpath + filename3, out)

# 圖像亮度調(diào)節(jié)

def img_brightness(image):

contrast = 1 # 對比度

brightness = 100 # 亮度

pic_turn = cv2.addWeighted(image, contrast, image, 0, brightness)

# cv2.addWeighted(對象,對比度,對象,對比度)

'''cv2.addWeighted()實(shí)現(xiàn)的是圖像透明度的改變與圖像的疊加'''

cv2.imshow('bright', pic_turn) # 顯示圖片

filename3=str(number)+'n11'+'.jpg'

cv2.imwrite(savedpath + filename3, pic_turn)

if __name__ == '__main__':

i = 0

path = '../Data/'

print(path)

savedpath = './result_new/'

filelist = os.listdir(path)

total_num = len(filelist)

for item in filelist:

number = i + 1

i = number

print("######")

print("打印到第",i,"張圖片")

src = cv2.imread(path + item)

img_translation(src)

img_scale(src)

img_flip(src)

img_rotation(src)

img_noise(src)

img_brightness(src)

cv2.waitKey(0)

cv2.destroyAllWindows()

代碼較為繁瑣,有空之后進(jìn)行優(yōu)化

輸出結(jié)果

網(wǎng)頁標(biāo)題:python下載圖片函數(shù) python批量下載圖片代碼
URL鏈接:http://www.ekvhdxd.cn/article1/doihpid.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供動(dòng)態(tài)網(wǎng)站、手機(jī)網(wǎng)站建設(shè)營銷型網(wǎng)站建設(shè)、Google網(wǎng)站導(dǎo)航、建站公司

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都seo排名網(wǎng)站優(yōu)化