In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article focuses on "how to achieve cool 3D rotation with Python and Matlab". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to achieve cool 3D rotation with Python and Matlab.
1.Python crawled beauty photos 1.1 nostalgia for the web site
Webmaster material-A platform for sharing comprehensive design material (chinaz.com)
1.2 Python Code # ~ ~ Welcome to the official account: beauty of Power system and algorithm ~ # ~ Import related Library ~ import urllib.requestfrom lxml import etree # ~ 1. Customization of request object ~ def create_request (page): if (page = = 1): url = 'https://sc.chinaz.com/tag_tupian/YaZhouMeiNv.html' else: url =' https://sc.chinaz.com/tag_tupian/yazhoumeinv_' + str (page) + '.html' # print (url) headers = {'User-Agent':' Mozilla/5.0 (Windows NT 6.1; Win64) X64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.104 Safari/537.36'} request = urllib.request.Request (url=url, headers=headers) return request # ~ 2. Get the source code of the page ~ def get_content (request): response = urllib.request.urlopen (request) content = response.read (). Decode ('utf-8') return content # ~ 3. Download pictures ~ ~ def down_img (content): # download file format: urllib.request.urlretrieve ('image address', 'name of the file') tree = etree.HTML (content) name_list = tree.xpath ('/ / div [@ id = "container"] / / a tree.xpath) # generally websites involving images will load lazily and replace src with src2 (lazy loading) Src will appear as src2) src_list = tree.xpath ('/ / div [@ id = "container"] / / print IMG _ Actionsrc2') # print (len (name_list)) # print (len (src_list)) for i in range (len (name_list): name = name_ list [I] src = src_list [I] url = 'https:' + src url = url.replace (' _ s') '') urllib.request.urlretrieve (url=url, filename='./meinv/' + name + '.jpg') # ~ run ~ if _ _ name__ = ='_ main__': start_page = int (input ('please enter the starting page number:') end_page = int (input ('please enter the termination page number:') for page in range (start_page, end_page + 1): # ~ ~ 1. Custom request object ~ request = create_request (page) # ~ ~ 2. Get web page source code ~ content = get_content (request) # ~ 3. Parse the source code and download the picture ~ down_img (content) 1.3results
Warm Tip: meinv this folder is set up in advance.
Condition preparation for 2.Python implementation 2.1,
The photos crawled from 1, we can prepare for the next thing. Select 12 photos, as shown in the figure:
2.2 run the show
Running it is cooler than the following:
2.3 Python realizes the special effect of CSS3 to create 3D picture cube rotation.
3.Matlab implementation 3.1 run demonstration
Dynamic video:
3.2 Matlab code% = Welcome to the interest number: beauty of Power Systems and algorithms function wlz3dpath='.\ meinv\';% folder name files=dir (fullfile (path,'*.jpg')); picNum=size (files,1);% traversal path each image for i=1:picNum fileName=strcat (path,files (I) .name); img=imread (fileName); img=imresize (img, [120120]); imgSet {I} = img End% fig axes sets fig=figure ('units','pixels','position', [50 50 600 600],... 'Numbertitle','off','resize','off',... 'name','album3d','menubar','none'); ax=axes (' parent',fig,'position', [- 0.5-0.522], 'XLim', [- 66],... 'YLim', [- 66],... 'ZLim', [- 66],... 'Visible','on',... 'XTick', [],... 'YTick', [],... 'Color', [0 000],... 'DataAspectRatioMode','manual',... 'CameraPositionMode','manual'); hold (ax,'on') ax.CameraPosition= [555];% grids for drawing pictures [XMesh,YMesh] = meshgrid (linspace (- 1Power1120), linspace (- 1Power1120)); ZMesh=ones (120120);% drawing picture cubes surfPic (1) = surf (XMesh,YMesh,ZMesh,'CData',imgSet {mod + 1},' EdgeColor','none','FaceColor','interp') SurfPic (2) = surf (XMesh,YMesh (end:-1:1,:),-ZMesh,'CData',imgSet {mod (1pm picNum) + 1}, 'EdgeColor','none','FaceColor','interp'); surfPic (3) = surf (ZMesh,XMesh,YMesh (end:-1:1,:),' CData',imgSet {mod (2pic Num) + 1}, 'EdgeColor','none','FaceColor','interp') SurfPic (4) = surf (XMesh,ZMesh,YMesh (end:-1:1,:), 'CData',imgSet {mod (3pics picNum) + 1},' EdgeColor','none','FaceColor','interp'); surfPic (5) = surf (- ZMesh,XMesh,YMesh (end:-1:1,:), 'CData',imgSet {mod (4picNum) + 1},' EdgeColor','none','FaceColor','interp') SurfPic (6) = surf (XMesh,-ZMesh,YMesh (end:-1:1,:), 'CData',imgSet {mod (5scorePicNum) + 1},' EdgeColor','none','FaceColor','interp');% rely on small cube data to draw medium cube for iPic 1R 6 surfPicA (I) = surf (surfPic (I). XData.*1.5,surfPic (I) .YData. * 1.5 line surfPic (I) .ZData. 'CData',surfPic (I) .CData,' EdgeColor','none','FaceColor','interp','FaceAlpha',0.7); end%% is used to adjust the magnification of the matrix resizeMat= [2 2 2.5 10 2 2 2 5 10 2 2 2 5 2 10 2 2 2 5 2] %% maximum picture rendering% for iPicture 1 6% surfPicB (I) = surf (surfPic (I) .XData. * resizeMat (iMagne 1),...% surfPic (I) .YData. * resizeMat (iMagazine 2),...% surfPic (I) .ZData. * resizeMat (iMagazine 3),...% 'CData',surfPic (I). CData 'EdgeColor',...%' none','FaceColor','interp','FaceAlpha',0.7) % end lastDis=300;preDis=300;set (fig,'WindowButtonMotionFcn',@move2center) function move2center (~, ~) xy=get (fig,'CurrentPoint'); preDis=sqrt (sum ((xy- [300300]). ^ 2)); end fps=40;theta=0;rotateTimer=timer ('ExecutionMode',' FixedRate', 'Period',1/fps,' TimerFcn', @ rotateCube); start (rotateTimer) function rotateCube (~, ~) theta=theta+0.02 Ax.CameraPosition= [cos (theta) * 5*sqrt (2), sin (theta) * 5*sqrt (2), 5]; if (~ all ([preDis lastDis])
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.