Android 手把手帶你玩轉自己定義相機

本文已授權微信公眾號《鴻洋》原創首發,轉載請務必注明出處。

概述

相機差點兒是每一個APP都要用到的功能,萬一老板讓你定制相機方不方?反正我是有點方。

關于相機的兩天奮斗總結免費送給你。

  Intent intent = new Intent();  intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);  startActivity(intent);

或者指定返回圖片的名稱mCurrentPhotoFile

  Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);intent.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(mCurrentPhotoFile));startActivityForResult(intent, CAMERA_WITH_DATA);

2.自己定義啟動相機。

今天以另外一種為例。

效果圖例如以下
demo

自己定義相機的一般步驟

  1. 創建顯示相機畫面的布局。Android已經為我們選定好SurfaceView
  2. 通過SurfaceView#getHolder()獲得鏈接CameraSurfaceViewSurfaceHolder
  3. Camame.open()打開相機
  4. 通過SurfaceHolder鏈接CameraurfaceView

一般步驟的代碼演示

public class CameraSurfaceView extends SurfaceView implements SurfaceHolder.Callback, Camera.AutoFocusCallback {private static final String TAG = "CameraSurfaceView";private Context mContext;private SurfaceHolder holder;private Camera mCamera;private int mScreenWidth;private int mScreenHeight;public CameraSurfaceView(Context context) {this(context, null);}public CameraSurfaceView(Context context, AttributeSet attrs) {this(context, attrs, 0);}public CameraSurfaceView(Context context, AttributeSet attrs, int defStyleAttr) {super(context, attrs, defStyleAttr);mContext = context;getScreenMetrix(context);initView();}private void getScreenMetrix(Context context) {WindowManager WM = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);DisplayMetrics outMetrics = new DisplayMetrics();WM.getDefaultDisplay().getMetrics(outMetrics);mScreenWidth = outMetrics.widthPixels;mScreenHeight = outMetrics.heightPixels;}private void initView() {holder = getHolder();//獲得surfaceHolder引用holder.addCallback(this);holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);//設置類型}@Overridepublic void surfaceCreated(SurfaceHolder holder) {Log.i(TAG, "surfaceCreated");if (mCamera == null) {mCamera = Camera.open();//開啟相機try {mCamera.setPreviewDisplay(holder);//攝像頭畫面顯示在Surface上} catch (IOException e) {e.printStackTrace();}}}@Overridepublic void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {Log.i(TAG, "surfaceChanged");mCamera.startPreview();}@Overridepublic void surfaceDestroyed(SurfaceHolder holder) {Log.i(TAG, "surfaceDestroyed");mCamera.stopPreview();//停止預覽mCamera.release();//釋放相機資源mCamera = null;holder = null;}@Overridepublic void onAutoFocus(boolean success, Camera Camera) {if (success) {Log.i(TAG, "onAutoFocus success="+success);}}
}

加入相機和自己主動聚焦限權

<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera.autofocus" />

CameraSurfaceView放在布局文件里,這里建議最外層為FrameLayout,后面會用到。如此。我們便有了一個沒有照相功能的相機。初次之外,細致觀察相機顯示畫面,圖片是不是變形嚴重?那是由于我們還沒有為相機設置各種參數。在預覽前要設置攝像頭的分辨率、預覽分辨率和圖片分辨率的寬高比保持一致。這樣圖片才不會變形。這是個比較難以理解的部分,想深刻理解還需讀者自己動手去實踐。

   private void setCameraParams(Camera camera, int width, int height) {Log.i(TAG,"setCameraParams  width="+width+"  height="+height);Camera.Parameters parameters = mCamera.getParameters();// 獲取攝像頭支持的PictureSize列表List<Camera.Size> pictureSizeList = parameters.getSupportedPictureSizes();for (Camera.Size size : pictureSizeList) {Log.i(TAG, "pictureSizeList size.width=" + size.width + "  size.height=" + size.height);}/**從列表中選取合適的分辨率*/Camera.Size picSize = getProperSize(pictureSizeList, ((float) height / width));if (null == picSize) {Log.i(TAG, "null == picSize");picSize = parameters.getPictureSize();}Log.i(TAG, "picSize.width=" + picSize.width + "  picSize.height=" + picSize.height);// 依據選出的PictureSize又一次設置SurfaceView大小float w = picSize.width;float h = picSize.height;parameters.setPictureSize(picSize.width,picSize.height);this.setLayoutParams(new FrameLayout.LayoutParams((int) (height*(h/w)), height));// 獲取攝像頭支持的PreviewSize列表List<Camera.Size> previewSizeList = parameters.getSupportedPreviewSizes();for (Camera.Size size : previewSizeList) {Log.i(TAG, "previewSizeList size.width=" + size.width + "  size.height=" + size.height);}Camera.Size preSize = getProperSize(previewSizeList, ((float) height) / width);if (null != preSize) {Log.i(TAG, "preSize.width=" + preSize.width + "  preSize.height=" + preSize.height);parameters.setPreviewSize(preSize.width, preSize.height);}parameters.setJpegQuality(100); // 設置照片質量if (parameters.getSupportedFocusModes().contains(android.hardware.Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) {parameters.setFocusMode(android.hardware.Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);// 連續對焦模式}mCamera.cancelAutoFocus();//自己主動對焦。

// 設置PreviewDisplay的方向。效果就是將捕獲的畫面旋轉多少度顯示 // TODO 這里直接設置90°不嚴謹。詳細見https://developer.android.com/reference/android/hardware/Camera.html#setPreviewDisplay%28android.view.SurfaceHolder%29 mCamera.setDisplayOrientation(90); mCamera.setParameters(parameters); } /** * 從列表中選取合適的分辨率 * 默認w:h = 4:3 * <p>tip:這里的w相應屏幕的height * h相應屏幕的width<p/> */ private Camera.Size getProperSize(List<Camera.Size> pictureSizeList, float screenRatio) { Log.i(TAG, "screenRatio=" + screenRatio); Camera.Size result = null; for (Camera.Size size : pictureSizeList) { float currentRatio = ((float) size.width) / size.height; if (currentRatio - screenRatio == 0) { result = size; break; } } if (null == result) { for (Camera.Size size : pictureSizeList) { float curRatio = ((float) size.width) / size.height; if (curRatio == 4f / 3) {// 默認w:h = 4:3 result = size; break; } } } return result; }

進去的是屏幕寬高。出來的是調整好了的參數。在surfaceChanged方法中運行mCamera.startPreview(); 前調用setCameraParams(mCamera, mScreenWidth, mScreenHeight); 就能夠了。最后要在AndroidManifest.xml里設置activity的方向android:screenOrientation="portrait"代碼里有非常多凝視,當中也有我自己調試時候的Log,大家能夠自己調試下。看看不同參數的效果。昨天調參數搞到一點多,都在折騰這個函數。

唉,一把辛酸淚。
身為一個相機,竟然不能照相?真是太丟臉了!

以下給我們的相機加入上照相的功能。照相核心代碼就一句:mCamera.takePicture(null, null, jpeg);
能夠看到takePicture方法有三個參數,各自是ShutterCallbackPictureCallbackPictureCallback。這里我們僅僅用了PictureCallback

    // 拍照瞬間調用private Camera.ShutterCallback shutter = new Camera.ShutterCallback() {@Overridepublic void onShutter() {Log.i(TAG,"shutter");}};// 獲得沒有壓縮過的圖片數據private Camera.PictureCallback raw = new Camera.PictureCallback() {@Overridepublic void onPictureTaken(byte[] data, Camera Camera) {Log.i(TAG, "raw");}};//創建jpeg圖片回調數據對象private Camera.PictureCallback jpeg = new Camera.PictureCallback() {@Overridepublic void onPictureTaken(byte[] data, Camera Camera) {BufferedOutputStream bos = null;Bitmap bm = null;try {// 獲得圖片bm = BitmapFactory.decodeByteArray(data, 0, data.length);if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {Log.i(TAG, "Environment.getExternalStorageDirectory()="+Environment.getExternalStorageDirectory());String filePath = "/sdcard/dyk"+System.currentTimeMillis()+".jpg";//照片保存路徑File file = new File(filePath);if (!file.exists()){file.createNewFile();}bos = new BufferedOutputStream(new FileOutputStream(file));bm.compress(Bitmap.CompressFormat.JPEG, 100, bos);//將圖片壓縮到流中}else{Toast.makeText(mContext,"沒有檢測到內存卡", Toast.LENGTH_SHORT).show();}} catch (Exception e) {e.printStackTrace();} finally {try {bos.flush();//輸出bos.close();//關閉bm.recycle();// 回收bitmap空間mCamera.stopPreview();// 關閉預覽mCamera.startPreview();// 開啟預覽} catch (IOException e) {e.printStackTrace();}}}};

jpeg#onPictureTaken()里。我們將存儲照片信息的byte[] data解析成bitmap,然后轉換成JPG格式的圖片保存在SD卡中。注意finally中最后兩句mCamera.stopPreview();// 關閉預覽 mCamera.startPreview();// 開啟預覽 上文也提到:當調用camera.takePiture()方法后。camera關閉了預覽。這時須要調用startPreview()來又一次開啟預覽。假設不再次開啟預覽。則會一直停留在拍攝照片畫面。為了方便外部調用拍照。這里我暴露了一個方法供外部拍照。

    public void takePicture(){//設置參數,并拍照setCameraParams(mCamera, mScreenWidth, mScreenHeight);// 當調用camera.takePiture方法后,camera關閉了預覽,這時須要調用startPreview()來又一次開啟預覽mCamera.takePicture(null, null, jpeg);}

在布局文件里加入一個Button,點擊Button運行takePicture()方法。

不要忘了加入寫SD卡限權

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

至此。一個具有照相并保存拍攝圖片功能的相機就做出來了。

But,我們就此滿足了嗎?要是為了這些簡單的功能我也不會寫這篇博客。這僅僅是個開始

真正的開始

別人APP在照相的時候。屏幕上竟然能夠顯示像效果圖那樣的框框啦、輔助點啦、圖片bulabulabula~。

在網上搜索一番實現方式,再加上一些自己的理解,構成了這篇博客。
上文布局文件一直沒有貼。如今貼出來大家先掃一眼,有些控件會在接下來展示

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"><com.dyk.cameratest.view.CameraSurfaceView
        android:id="@+id/cameraSurfaceView"android:layout_width="match_parent"android:layout_height="match_parent" /><com.dyk.cameratest.view.RectOnCamera
        android:layout_width="match_parent"android:layout_height="match_parent" /><RelativeLayout
        android:layout_width="match_parent"android:layout_height="match_parent"><Button
            android:layout_alignParentBottom="true"android:layout_centerHorizontal="true"android:layout_marginBottom="20dp"android:id="@+id/takePic"android:layout_width="80dp"android:layout_height="50dp"android:background="#88427ac7"android:text="拍照"android:textColor="#aaa" /></RelativeLayout>
</FrameLayout>

布局文件的最外層是個FrameLayout。我們知道FrameLayout是自帶覆蓋效果的。由來這個思路接下來就非常easy了。

編程重要的是思想,思想有了,其余的就剩詳細的實現細節。

自己定義邊邊框框

為了和CameraSurfaceView區分開,再自己定義一個RectOnCamera專門用來畫邊邊框框這些東西。這樣做還一個優點是方便維護,不至于將所有東西都放在一個View中。

RectOnCamera

package com.dyk.cameratest.view;
...
/*** Created by 一口仨饃 on 2016/4/7.*/
public class RectOnCamera extends View {private static final String TAG = "CameraSurfaceView";private int mScreenWidth;private int mScreenHeight;private Paint mPaint;private RectF mRectF;// 圓private Point centerPoint;private int radio;public RectOnCamera(Context context) {this(context, null);}public RectOnCamera(Context context, AttributeSet attrs) {this(context, attrs, 0);}public RectOnCamera(Context context, AttributeSet attrs, int defStyleAttr) {super(context, attrs, defStyleAttr);getScreenMetrix(context);initView(context);}private void getScreenMetrix(Context context) {WindowManager WM = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);DisplayMetrics outMetrics = new DisplayMetrics();WM.getDefaultDisplay().getMetrics(outMetrics);mScreenWidth = outMetrics.widthPixels;mScreenHeight = outMetrics.heightPixels;}private void initView(Context context) {mPaint = new Paint();mPaint.setAntiAlias(true);// 抗鋸齒mPaint.setDither(true);// 防抖動mPaint.setColor(Color.RED);mPaint.setStrokeWidth(5);mPaint.setStyle(Paint.Style.STROKE);// 空心int marginLeft = (int) (mScreenWidth*0.15);int marginTop = (int) (mScreenHeight * 0.25);mRectF = new RectF(marginLeft, marginTop, mScreenWidth - marginLeft, mScreenHeight - marginTop);centerPoint = new Point(mScreenWidth/2, mScreenHeight/2);radio = (int) (mScreenWidth*0.1);}@Overrideprotected void onDraw(Canvas canvas) {super.onDraw(canvas);mPaint.setColor(Color.RED);canvas.drawRect(mRectF, mPaint);mPaint.setColor(Color.WHITE);Log.i(TAG, "onDraw");canvas.drawCircle(centerPoint.x,centerPoint.y, radio,mPaint);// 外圓canvas.drawCircle(centerPoint.x,centerPoint.y, radio - 20,mPaint); // 內圓}
}

這里簡單的畫了一個相似二維碼掃描的框框。另一個相似聚焦的內外圓。那么問題來了,聚焦的內外圓要隨著手指滑而改變位置,并且要有聚焦的效果。可又和具有聚焦功能的CameraSurfaceView不是同一個類。不僅如此聚焦內外圓還全然覆蓋了CameraSurfaceView。要處理這樣的問題,須要接口回調。這就是思想以下的細節。如今盡管確定接口回調。但另一個問題,CameraSurfaceView類和RectOnCamera類中都沒有對方的對象或者引用。沒錯,通過共同持有RectOnCameraCameraSurfaceViewActivity能夠實現此功能。以下是詳細的實現方法

動起來

首先。想要隨著手指的滑動而改變RectOnCamera的位置肯定是要復寫onTouchEvent()方法

    @Overridepublic boolean onTouchEvent(MotionEvent event) {switch (event.getAction()){case MotionEvent.ACTION_DOWN:case MotionEvent.ACTION_MOVE:case MotionEvent.ACTION_UP:int x = (int) event.getX();int y = (int) event.getY();centerPoint = new Point(x, y);invalidate();return true;}return true;}

其次,定義回調接口

 private IAutoFocus mIAutoFocus;/** 聚焦的回調接口 */public interface  IAutoFocus{void autoFocus();}public void setIAutoFocus(IAutoFocus mIAutoFocus) {this.mIAutoFocus = mIAutoFocus;}

onTouchEvent()return前加入

  if (mIAutoFocus != null){mIAutoFocus.autoFocus();}

至此我們的回調接口已經定義好了。此時還須要CameraSurfaceView暴露一個聚焦方法。以便Activity調用

    public void setAutoFocus(){mCamera.autoFocus(this);}

準備工作已經所有完畢。以下請看Activity的詳細實現:

public class MainActivity extends Activity implements View.OnClickListener,RectOnCamera.IAutoFocus{private CameraSurfaceView mCameraSurfaceView;private RectOnCamera mRectOnCamera;private Button takePicBtn;private boolean isClicked;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);requestWindowFeature(Window.FEATURE_NO_TITLE);// 全屏顯示     getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);setContentView(R.layout.activity_main);mCameraSurfaceView = (CameraSurfaceView) findViewById(R.id.cameraSurfaceView);mRectOnCamera = (RectOnCamera) findViewById(R.id.rectOnCamera);takePicBtn= (Button) findViewById(R.id.takePic);mRectOnCamera.setIAutoFocus(this);takePicBtn.setOnClickListener(this);}@Overridepublic void onClick(View v) {switch (v.getId()){case R.id.takePic:mCameraSurfaceView.takePicture();break;default:break;}}@Overridepublic void autoFocus() {mCameraSurfaceView.setAutoFocus();}
}

能夠看到,MainActivity實現了IAutoFocus接口,并且在復寫的IAutoFocus#autoFocus()方法中。調用了CameraSurfaceView暴露出來的方法setAutoFocus()。至此,在RectOnCamera每次的滑動過程中都會改變聚焦內外圓的位置,還會添加聚焦功能。

一心二用甚至一心多用豈不是更好。

結束語

在經歷兩次斷電沒保存和一次CSDNserver錯誤內容丟失之后終究還是完畢了這篇博客,實屬不易。十分感謝能聽我啰嗦到結尾~

PS:Demo界面并沒有做的非常精致,僅僅是提供了一種思路。依照此思路能做出比較華麗的效果,授人以魚不如授人以漁。

2016.10.12 在經歷了上述種種磨難之后。最終發表了這篇博文。然而發表沒幾天,被我自己覆蓋了。這下博文是真的丟了。心塞ing。今天沒事百度下自己CSDN昵稱“一口仨饃”,發現其它站點爬過這篇博文。隨后我復制了自己原創的博文,再次發表。感謝那些爬我博文還不署名的站點。

謝謝你全家。

源代碼下載

http://download.csdn.net/detail/qq_17250009/9484160

轉載于:https://www.cnblogs.com/yfceshi/p/7382534.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/391629.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/391629.shtml
英文地址,請注明出處:http://en.pswp.cn/news/391629.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

如何在JavaScript中克隆數組

JavaScript has many ways to do anything. I’ve written on 10 Ways to Write pipe/compose in JavaScript, and now we’re doing arrays.JavaScript有許多方法可以執行任何操作。 我已經寫了10種用JavaScript編寫管道/組合的方法 &#xff0c;現在我們正在做數組。 1.傳播…

leetcode 227. 基本計算器 II(棧)

給你一個字符串表達式 s &#xff0c;請你實現一個基本計算器來計算并返回它的值。 整數除法僅保留整數部分。 示例 1&#xff1a; 輸入&#xff1a;s “32*2” 輸出&#xff1a;7 解題思路 利用兩個棧&#xff0c;一個記錄操作數&#xff0c;一個記錄操作符&#xff0c;…

100米隊伍,從隊伍后到前_我們的隊伍

100米隊伍,從隊伍后到前The last twelve months have brought us a presidential impeachment trial, the coronavirus pandemic, sweeping racial justice protests triggered by the death of George Floyd, and a critical presidential election. News coverage of these e…

idea使用 git 撤銷commit

2019獨角獸企業重金招聘Python工程師標準>>> 填寫commit的id 就可以取消這一次的commit 轉載于:https://my.oschina.net/u/3559695/blog/1596669

ES6標準入門(第二版)pdf

下載地址&#xff1a;網盤下載 內容簡介 ES6&#xff08;又名 ES2105&#xff09;是 JavaScript 語言的新標準&#xff0c;2015 年 6 月正式發布后&#xff0c;得到了迅速推廣&#xff0c;是目前業界超級活躍的計算機語言。《ES6標準入門&#xff08;第2版&#xff09;》…

hexo博客添加暗色模式_我如何向網站添加暗模式

hexo博客添加暗色模式同一個網站&#xff0c;兩種不同的配色方案 (Same website, two different color schemes) Last year I made it a point to redesign my website from scratch. I wanted something simple and minimalist looking that clearly stated what this was — …

leetcode 331. 驗證二叉樹的前序序列化

序列化二叉樹的一種方法是使用前序遍歷。當我們遇到一個非空節點時&#xff0c;我們可以記錄下這個節點的值。如果它是一個空節點&#xff0c;我們可以使用一個標記值記錄&#xff0c;例如 #。_9_/ \3 2/ \ / \4 1 # 6 / \ / \ / \ # # # # # # 例如&#xff0…

mongodb數據可視化_使用MongoDB實時可視化開放數據

mongodb數據可視化Using Python to connect to Taiwan Government PM2.5 open data API, and schedule to update data in real time to MongoDB — Part 2使用Python連接到臺灣政府PM2.5開放數據API&#xff0c;并計劃將數據實時更新到MongoDB —第2部分 目標 (Goal) This ti…

4.kafka的安裝部署

為了安裝過程對一些參數的理解&#xff0c;我先在這里提一下kafka一些重點概念,topic,broker,producer,consumer,message,partition,依賴于zookeeper, kafka是一種消息隊列,他的服務端是由若干個broker組成的&#xff0c;broker會向zookeeper&#xff0c;producer生成者對應一個…

javascript初學者_針對JavaScript初學者的調試技巧和竅門

javascript初學者by Priyanka Garg由Priyanka Garg My intended audience for this tutorial is beginner programmers. You’ll learn about frustration-free debugging with chrome dev tools.本教程的目標讀者是初學者。 您將學習使用chrome開發工具進行無挫折的調試。 D…

leetcode 705. 設計哈希集合

不使用任何內建的哈希表庫設計一個哈希集合&#xff08;HashSet&#xff09;。 實現 MyHashSet 類&#xff1a; void add(key) 向哈希集合中插入值 key 。 bool contains(key) 返回哈希集合中是否存在這個值 key 。 void remove(key) 將給定值 key 從哈希集合中刪除。如果哈希…

ecshop 前臺個人中心修改側邊欄 和 側邊欄顯示不全 或 導航現實不全

怎么給個人中心側邊欄加項或者減項 在模板文件default/user_menu.lbi 文件里添加或者修改,一般看到頁面都會知道怎么加,怎么刪,這里就不啰嗦了 添加一個欄目以后,這個地址跳的頁面怎么寫 這是最基本的一個包括左側個人信息,頭部導航欄 <!DOCTYPE html PUBLIC "-//W3C//…

leetcode 706. 設計哈希映射

不使用任何內建的哈希表庫設計一個哈希映射&#xff08;HashMap&#xff09;。 實現 MyHashMap 類&#xff1a; MyHashMap() 用空映射初始化對象 void put(int key, int value) 向 HashMap 插入一個鍵值對 (key, value) 。如果 key 已經存在于映射中&#xff0c;則更新其對應…

數據庫語言 數據查詢_使用這種簡單的查詢語言開始查詢數據

數據庫語言 數據查詢Working with data is becoming an increasingly important skill in the modern workplace. 在現代工作場所中&#xff0c;處理數據已成為越來越重要的技能。 Data is no longer the domain of analysts and software engineers. With todays technology,…

面向對象編程思想-觀察者模式

一、引言 相信猿友都大大小小經歷過一些面試&#xff0c;其中有道經典題目&#xff0c;場景是貓咪叫了一聲&#xff0c;老鼠跑了&#xff0c;主人被驚醒&#xff08;設計有擴展性的可加分&#xff09;。對于初學者來說&#xff0c;可能一臉懵逼&#xff0c;這啥跟啥啊是&#x…

typescript 使用_如何使用TypeScript輕松修改Minecraft

typescript 使用by Josh Wulf通過喬什沃爾夫(Josh Wulf) 如何使用TypeScript輕松修改Minecraft (How to modify Minecraft the easy way with TypeScript) Usually, modifying Minecraft requires coding in Java, and a lot of scaffolding. Now you can write and share Min…

Python:在Pandas數據框中查找缺失值

How to find Missing values in a data frame using Python/Pandas如何使用Python / Pandas查找數據框中的缺失值 介紹&#xff1a; (Introduction:) When you start working on any data science project the data you are provided is never clean. One of the most common …

監督學習-回歸分析

一、數學建模概述 監督學習&#xff1a;通過已有的訓練樣本進行訓練得到一個最優模型&#xff0c;再利用這個模型將所有的輸入映射為相應的輸出。監督學習根據輸出數據又分為回歸問題&#xff08;regression&#xff09;和分類問題&#xff08;classfication&#xff09;&#…

leetcode 54. 螺旋矩陣(遞歸)

給你一個 m 行 n 列的矩陣 matrix &#xff0c;請按照 順時針螺旋順序 &#xff0c;返回矩陣中的所有元素。 示例 1&#xff1a; 輸入&#xff1a;matrix [[1,2,3],[4,5,6],[7,8,9]] 輸出&#xff1a;[1,2,3,6,9,8,7,4,5] 示例 2&#xff1a; 輸入&#xff1a;matrix [[1,…

微服務架構技能

2019獨角獸企業重金招聘Python工程師標準>>> 微服務架構技能 博客分類&#xff1a; 架構 &#xff08;StuQ 微服務技能圖譜&#xff09; 2課程簡介 本課程分為基礎篇和高級篇兩部分&#xff0c;旨在通過完整的案例&#xff0c;呈現微服務的開發、測試、構建、部署、…