欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python&Matlab實現(xiàn)炫酷的3D旋轉圖

 更新時間:2022年04月19日 09:18:50   作者:電力系統(tǒng)與算法之美  
這篇文章主要為大家介紹了如何利用Python和Matlab分別實現(xiàn)酷炫的3D旋轉圖,文中的示例代碼講解詳細,感興趣的可以了解一下

前言

我們今天的任務很明確,我先系統(tǒng)梳理一下:

1.先用Python爬取一波漂亮的美女照片;

2.然后Python中炫酷的代碼實現(xiàn);

3.最后用matlab伺候,得到相同的結果。

1.Python爬取美女照片 

1.1 留戀忘返的網(wǎng)址

站長素材-分享綜合設計素材的平臺 (chinaz.com)

1.2 Python代碼

 
#~~~~歡迎關注公眾號:電力系統(tǒng)與算法之美~~~~~~~~~~~~·
 
#~~~~~~~~~導入相關庫~~~~~~~~~~~~~~~~~~~~·
import urllib.request
from lxml import etree
 
#~~~~~~~~~1.請求對象的定制~~~~~~~~~~~~~~~~~
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.獲取網(wǎng)頁的源碼~~~~~~~~~~~~~~~~~~~~~
def get_content(request):
    response = urllib.request.urlopen(request)
    content = response.read().decode('utf-8')
    return content
 
 
#~~~~~~~~~~~~~~~~~~~3.下載圖片~~~~~~~~~~~~~~~~~~~~~~~~~~
def down_img(content):
    # 下載文件格式:urllib.request.urlretrieve('圖片地址','文件的名字')
    tree = etree.HTML(content)
    name_list = tree.xpath('//div[@id = "container"]//a/img/@alt')
    # 一般涉及到圖片的網(wǎng)站,都會進行懶加載,要把src換成src2(懶加載時,src會以src2出現(xiàn))
    src_list = tree.xpath('//div[@id = "container"]//a/img/@src2')
    # 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')
 
#~~~~~~~~~運行~~~~~~~~~~~~~~~
if __name__ == '__main__':
    start_page = int(input('請輸入起始頁碼:'))
    end_page = int(input('請輸入終止頁碼:'))
 
    for page in range(start_page, end_page + 1):
        #~~~~1.定制請求對象~~~~~
        request = create_request(page)
        #~~~~2.獲取網(wǎng)頁源碼~~~~~
        content = get_content(request)
        #~~~~~3.解析源碼并下載圖片~~~
        down_img(content)

1.3 結果 

溫馨提示:meinv這個文件夾是提前建立的。 

2.Python實現(xiàn)

2.1 條件準備

由1中爬取的照片,我們就可以為接下來的事做準備啦。選取十二張照片,如圖:

2.2 運行展示 

運行出來比下面這個還炫酷:

2.3 Python實現(xiàn)

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>CSS3制作3D圖片立方體旋轉特效</title>
<link rel="stylesheet" href="css/index.css" rel="external nofollow" >
</head>
<body>
<!--/*外層最大容器*/-->
<div class="wrap">
<!--	/*包裹所有元素的容器*/-->
<div class="cube">
	<!--前面圖片 -->
	<div class="out_front">
		<img src="img/1.jpg" class="pic">
	</div>
	<!--后面圖片 -->
	<div class="out_back">
		<img src="img/2.jpg" class="pic">
	</div>
	<!--左圖片 -->
	<div class="out_left">
		<img src="img/3.jpg" class="pic">
	</div>
	<!--右圖片 -->
	<div class="out_right">
		<img src="img/4.jpg" class="pic">
	</div>
	<!--上圖片 -->
	<div class="out_top">
		<img src="img/5.jpg" class="pic">
	</div>
	<!--下圖片 -->
	<div class="out_bottom">
		<img src="img/6.jpg" class="pic">
	</div>
	<!--小正方體 --> 
	<span class="in_front">
		<img src="img/7.jpg" class="in_pic">
	</span>
	<span class="in_back">
		 <img src="img/8.jpg" class="in_pic">
	</span>
	<span class="in_left">
		<img src="img/9.jpg" class="in_pic">
	</span>
	<span class="in_right">
		<img src="img/10.jpg" class="in_pic">
	</span>
	<span class="in_top">
		<img src="img/11.jpg" class="in_pic">
	</span>
	<span class="in_bottom">
		<img src="img/12.jpg" class="in_pic">
	</span>
</div>
</div>
</body>
</html>

3.Matlab實現(xiàn)

3.1 運行展示

動態(tài)視頻:

3.2 Matlab代碼

%====歡迎關注關注號:電力系統(tǒng)與算法之美
function wlz3d
path='.\meinv\';%文件夾名稱
files=dir(fullfile(path,'*.jpg')); 
picNum=size(files,1);
 
%% 遍歷路徑下每一幅圖像
for i=1:picNum
   fileName=strcat(path,files(i).name); 
   img=imread(fileName);
   img=imresize(img,[120,120]);
   imgSet{i}=img;
end
 
%% fig axes設置
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.5 2 2],...
   'XLim', [-6 6],...
   'YLim', [-6 6],...
   'ZLim', [-6 6],...
   'Visible','on',...
   'XTick',[], ...
   'YTick',[],...
   'Color',[0 0 0],...
   'DataAspectRatioMode','manual',...
   'CameraPositionMode','manual');
hold(ax,'on')
ax.CameraPosition=[5 5 5];
 
%% 用于繪制圖片的網(wǎng)格
[XMesh,YMesh]=meshgrid(linspace(-1,1,120),linspace(-1,1,120));
ZMesh=ones(120,120);
 
%% 繪制圖片立方體
surfPic(1)=surf(XMesh,YMesh,ZMesh,'CData',imgSet{mod(0,picNum)+1},'EdgeColor','none','FaceColor','interp');
surfPic(2)=surf(XMesh,YMesh(end:-1:1,:),-ZMesh,'CData',imgSet{mod(1,picNum)+1},'EdgeColor','none','FaceColor','interp');
surfPic(3)=surf(ZMesh,XMesh,YMesh(end:-1:1,:),'CData',imgSet{mod(2,picNum)+1},'EdgeColor','none','FaceColor','interp');
surfPic(4)=surf(XMesh,ZMesh,YMesh(end:-1:1,:),'CData',imgSet{mod(3,picNum)+1},'EdgeColor','none','FaceColor','interp');
surfPic(5)=surf(-ZMesh,XMesh,YMesh(end:-1:1,:),'CData',imgSet{mod(4,picNum)+1},'EdgeColor','none','FaceColor','interp');
surfPic(6)=surf(XMesh,-ZMesh,YMesh(end:-1:1,:),'CData',imgSet{mod(5,picNum)+1},'EdgeColor','none','FaceColor','interp');
 
%% 依靠小立方體數(shù)據(jù)繪制中等立方體
for i=1:6
    surfPicA(i)=surf(surfPic(i).XData.*1.5,surfPic(i).YData.*1.5,surfPic(i).ZData.*1.5,...
        'CData',surfPic(i).CData,'EdgeColor','none','FaceColor','interp','FaceAlpha',0.7);  
end
 
%% 用來調整放大比例的矩陣
resizeMat=[2 2 2.5;2 2 2.5;2.5 2 2;
           2 2.5 2;2.5 2 2;2 2.5 2];
 
%% 最大圖片繪制       
% for i=1:6
%     surfPicB(i)=surf(surfPic(i).XData.*resizeMat(i,1),...
%                      surfPic(i).YData.*resizeMat(i,2),...
%                      surfPic(i).ZData.*resizeMat(i,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-[300,300]).^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]<150))&&any([preDis lastDis]<150)
            for ii=1:6
                if preDis<150
                    surfPicA(ii).XData=surfPic(ii).XData.*resizeMat(ii,1);
                    surfPicA(ii).YData=surfPic(ii).YData.*resizeMat(ii,2);
                    surfPicA(ii).ZData=surfPic(ii).ZData.*resizeMat(ii,3);
                else
                    surfPicA(ii).XData=surfPic(ii).XData.*1.5;
                    surfPicA(ii).YData=surfPic(ii).YData.*1.5;
                    surfPicA(ii).ZData=surfPic(ii).ZData.*1.5;
                end
            end
        end
        lastDis=preDis;
    end
 
% 棄用方案:太卡
% set(fig,'WindowButtonMotionFcn',@move2center)    
%     function move2center(~,~)
%         xy=get(fig,'CurrentPoint');
%         dis=sum((xy-[300,300]).^2);
%         for ii=1:6
%             if dis<200
%                 surfPicA(ii).XData=surfPic(ii).XData.*resizeMat(ii,1);
%                 surfPicA(ii).YData=surfPic(ii).YData.*resizeMat(ii,2);
%                 surfPicA(ii).ZData=surfPic(ii).ZData.*resizeMat(ii,3);
%             else
%                 surfPicA(ii).XData=surfPic(ii).XData;
%                 surfPicA(ii).YData=surfPic(ii).YData;
%                 surfPicA(ii).ZData=surfPic(ii).ZData;
%             end    
%         end
%         
%         
%         
%     end
 
end

到此這篇關于Python&Matlab實現(xiàn)炫酷的3D旋轉圖的文章就介紹到這了,更多相關Python Matlab3D旋轉圖內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

  • Python爬蟲實現(xiàn)使用beautifulSoup4爬取名言網(wǎng)功能案例

    Python爬蟲實現(xiàn)使用beautifulSoup4爬取名言網(wǎng)功能案例

    這篇文章主要介紹了Python爬蟲實現(xiàn)使用beautifulSoup4爬取名言網(wǎng)功能,結合實例形式分析了Python基于beautifulSoup4模塊爬取名言網(wǎng)并存入MySQL數(shù)據(jù)庫相關操作技巧,需要的朋友可以參考下
    2019-09-09
  • Python類和實例的屬性機制原理詳解

    Python類和實例的屬性機制原理詳解

    這篇文章主要介紹了Python類和實例的屬性機制原理詳解,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2020-03-03
  • python圖像和辦公文檔處理總結

    python圖像和辦公文檔處理總結

    在本文里我們給大家整理了關于python圖像和辦公文檔處理的相關知識點內(nèi)容以及重點內(nèi)容總結,有需要的朋友們跟著學習下。
    2019-05-05
  • Python線程條件變量Condition原理解析

    Python線程條件變量Condition原理解析

    這篇文章主要介紹了Python線程條件變量Condition原理解析,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2020-01-01
  • 對PyTorch torch.stack的實例講解

    對PyTorch torch.stack的實例講解

    今天小編就為大家分享一篇對PyTorch torch.stack的實例講解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-07-07
  • Python函數(shù)返回值實例分析

    Python函數(shù)返回值實例分析

    這篇文章主要介紹了Python函數(shù)返回值,實例分析了Python中返回一個返回值與多個返回值的方法,需要的朋友可以參考下
    2015-06-06
  • python實現(xiàn)2048小游戲

    python實現(xiàn)2048小游戲

    本文給大家分享的是個人修改自某網(wǎng)友的Python實現(xiàn)2048小游戲的代碼,推薦給大家,有需要的小伙伴可以參考下。
    2015-03-03
  • 最新評論