利用CSDN将图片自动存入AI Studio :pic2bml

网友投稿 1078 2025-03-31

简 介:

编写了python程序 pic2bml 可以快速借助于CSDN的图片存储功能,将图片串入AI Studio。对于有少量临时图片传输编程,可以增加程序开发的效率。

关键词:

pic2bml,bml,csdn

背景介绍

文章目录

基本方案

使用命令

实现代码

总 结

背景介绍

文章目录

基本方案

使用命令

实现代码

总 结

AI Studio是百度提供的进行人工智能开发的平台。在提供了百度人工智能网络框架之外,利用AI Studio 可以将软件、数据库、模型训练和部署整合在一起。免去了个人在自己的计算机平台是好搭建平台和维护开发过程琐事。

在AI Studio界面中,提供了多种途径允许将自己的图片数据文件导入云端的计算机中:

直接利用文件上载的功能;这种上载的数据文件只能在一个工程项目中应用;

利用自行建立数据库的功能;这种方式可以允许在不同的工程之间共享数据库;

既然有了这些手段,为什么还需要编程将图片自动导入AI Studio呢?

主要还是为了能够产生自动化调试和测试使用。对于少量实时采集的图片,如果希望能够测试相关的算法,通过编程自动导入可以提高程序开发的效率。

1.1 基本方案

基本处理过程

将图片上载CSDN获得链接

在AI Studio BML中wget图片

存储在本地,或者直接应用

1.2 使用命令

# Transfer picture into BaiDu Machine Learning Lab. # Usage: pic2bml * [work/1.jpg] # transfer clipboard pic to BML # picid [] # transfer DOP id to BML # 0 [] # transfer DOP picture dop to BML # picfile [] # Transfer picfile to BML # # default directory: temp # source: * : Clipboard # 0 : DOP picture # digit: DOP id # picfile # dest: default: work/1.jpg # picfile: default directory : Work # =var : Set url variable

1

2

3

4

5

6

7

8

9

10

11

12

13

1.3 实现代码

#!/usr/local/bin/python # -*- coding: gbk -*- #============================================================ # PIC2BML.PY -- by Dr. ZhuoQing 2021-12-22 # # Transfer picture into BaiDu Machine Learning Lab. # Usage: pic2bml * [work/1.jpg] # transfer clipboard pic to BML # picid [] # transfer DOP id to BML # 0 [] # transfer DOP picture dop to BML # picfile [] # Transfer picfile to BML # # default directory: temp # source: * : Clipboard # 0 : DOP picture # digit: DOP id # picfile # dest: default: work/1.jpg # picfile: default directory : Work # =var : Set url variable # # Note: #============================================================ from headm import * from PIL import Image from io import BytesIO import win32clipboard import pyautogui #------------------------------------------------------------ csdn_window = '写文章-CSDN博客' AIStudio_Title = 'BML CodeLab' #------------------------------------------------------------ def send_to_clipboard(clip_type, data): win32clipboard.OpenClipboard() win32clipboard.EmptyClipboard() win32clipboard.SetClipboardData(clip_type, data) win32clipboard.CloseClipboard() #------------------------------------------------------------ def ClipboardCopyImage(imageFile): if not os.path.isfile(imageFile): return image = Image.open(imageFile) output = BytesIO() image.convert('RGB').save(output, 'BMP') data = output.getvalue()[14:] output.close() send_to_clipboard(win32clipboard.CF_DIB, data) #------------------------------------------------------------ def GetCSDNImageURL(): tspsendwindowkey(csdn_window, ' ',noreturn=1) tspsendwindowkey(csdn_window, 'z', control=1,noreturn=1) tspsendwindowkey(csdn_window, 'v', control=1,noreturn=1) for i in range(40): time.sleep(.5) readdata = tspread() if readdata[2] == 1: break if readdata[7] != 0: break if readdata[8] != 0: exit() if readdata[9] != 0: exit() tspsendwindowkey(csdn_window, 'c', control=1, noreturn=1) if clipboard.paste().find('在这里插入图片描述') >= 0: tspbeep(1500, 200) time.sleep(.25) break printf('\a') tspsendwindowkey(csdn_window, 'ac', control=1, noreturn=1) time.sleep(.1) pastestr = clipboard.paste().split('![在这里插入图片描述](') if len(pastestr) < 2: printf("Can not find the ![Insert picture] discriptor !\a") return '' tspsendwindowkey(csdn_window, 'z', control=1) pastestr = pastestr[1].split(')')[0] replacestr = '![在这里插入图片描述](%s)'%pastestr pastestr = pastestr.split('?')[0] return pastestr #------------------------------------------------------------ def GetCSDNImageUrl(imageFile): ClipboardCopyImage(imageFile) return GetCSDNImageURL() #------------------------------------------------------------ filename = '*' outfile = '/home/aistudio/work/1.jpg' #------------------------------------------------------------ if len(sys.argv) > 1: filename = sys.argv[1] if filename.isdigit(): picfile = tspgetdopfile(int(filename)) extstr = picfile.split('.')[-1].upper() if not extstr in 'JPG BMP'.split(): printf("%s is not picture!\a"%picfile) exit() filename = picfile if len(sys.argv) > 2: outfile = sys.argv[2] if outfile.find('.') < 0: if filename.find('.') > 0: fn = filename.split('.')[-1] outfile = outfile + '.' + fn else: outfile = outfile + '.jpg' if outfile.find('/home/aistudio/work') < 0: outfile = '/home/aistudio/work/' + outfile #------------------------------------------------------------ printf('%s --> %s\a'%(filename, outfile)) #------------------------------------------------------------ if filename.find('http') >= 0: urlstr = filename else: urlstr = GetCSDNImageUrl(filename) #------------------------------------------------------------ aiscmd = "!wget -q --output-document=%s %s"%(outfile, urlstr) clipboard.copy(aiscmd) rect = tspgetwindowrect(AIStudio_Title) pyautogui.click((rect[2] - 150), rect[1] + 320) tspsendwindowkey(AIStudio_Title, "a", control=1, noreturn=1) tspsendwindowkey(AIStudio_Title, "av", control=1, noreturn=1) tspsendwindowkey(AIStudio_Title, "\r", shift=1, noreturn=1) tspfocuswindow('TEASOFT:1') #------------------------------------------------------------ # END OF FILE : PIC2BML.PY #============================================================

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

利用CSDN将图片自动存入AI Studio :pic2bml

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

编

写了python程序 pic2bml 可以快速借助于CSDN的图片存储功能,将图片串入AI Studio。对于有少量临时图片传输编程,可以增加程序开发的效率。

AI

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:ERP系统提供竞争优势的4种方式
下一篇:wps表格怎么整体放大(wps表格怎么整体放大缩小)
相关文章