1 Star 0 Fork 0

daniel肥杰/WeChat-MiniProgram-WebAR

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
BSD-3-Clause
  1. Chinese README

  2. Chinese Source Code Analysis

Updated

Date Update
2021-12-11 New: Added a Image Tracker using OpenCV WebAssembly. Please see the "Image AR using OpenCV".
2021-09-07 New: Added a Color Tracker mode. Please see the "Color AR".
2021-08-15 New: Added a video mask mode for image AR. This is a CSS 3D transformation, which does not require three.js. Please see the "Image AR and Video Mask". Update: Replace the spirit geometry with a plane geometry.
2021-04-03 Update: The "access a camera" mode of Image AR is recoverd.
2021-03-15 New: The display of the AR mask is changed from 2D to 3D by three.js. Update: Because the "access a camera" mode is slow, it is removed.
2019-08-16 Update: The project structure has been modified. The color tracker and object tracker are removed. Fix "access a camera" mode that does not work properly on Android.
2019-08-06 Fix Issue: When function "wx.canvasToTempFilePath" is called frequently on Android Wechat, WeChat will be crashed.
2019-08-01 Update: The perspective transform is achieved.
2019-07-15 Update: The NFT(Natural Feature Tracking) is achieved.
2019-07-08 New: The affine transform is achieved.

Introduction on WeChat Web AR

This is a WeChat Web AR. On July 5, 2019, WeChat miniprogram supported AR. It was added a new API named "CameraFrameListener".

CameraFrameListener API

We can create AR effects with the new API. This demo demonstrates a AR tracker effect using "tracking.js" and "jsfeat" library.

The "tracking.js" brings computer vision algorithms and techniques into browser environment. The "jsfeat" is also a JavaScript computer vision library. We can do real-time image and face detection.

tracking.js and JSFeat

Index Page of the WeChat Mini-program

avatar

avatar

Image AR and 3D Mask

Use the demo to scan a pattern image below.

avatar

A cat beard is on the pattern image.

avatar

A effect of translating and scaling.

avatar

A effect of rotating.

avatar

Image AR using OpenCV

This is the same as above. Supports image rotation.

The image is rotated by 30 degrees.

avatar

The image is rotated by 90 degrees.

avatar

Image AR and Video Mask

Use the demo to scan a rotating image below.

avatar

A video player is on and aligned with the image.

avatar

Color AR

Use the demo to scan a yellow color. Expect a effect below.

avatar

A effect of hiddening.

avatar

Custom the color of the highlighted area.

avatar

Face AR

Use the demo to scan a face. Expect a effect below.

avatar

A effect of translating and scaling.

avatar

Because the landmarks of the demo are simple and basic, only a effect of translating and scaling is on a rotating image.

avatar

How to replace the "cat beard" image

You may replace the default url of a image for 2D mask.

File: /package_image_tracker/pages/photo/photo.js and package_face_tracker/pages/photo/photo.js

// a url of sprite image
const modelUrl = '../../utils/cat_beard.png';

The width and height of the "modelurl" image should be 256 x 256, 512 x 512 and 1024 x 1024 etc.

How to replace the pattern image for Image AR

File: /package_face_tracker/utils/imageBusiness.js

const patternImageUrl = '../../../face_pattern.jpg';

a pattern image

avatar

How to put a image on other positions for Image AR

Select a track point on a pattern image, the point is used to set the "cat beard" image.

File: /package_image_tracker/utils/modelBusiness.js

// a index of a track point on a pattern image
const trackPoint = { 
    x: 185, // the width of the pattern image is 375
    y: 224, // the height of the pattern image is 375
};

How to put a image on other positions for Face AR

This is a map of the 31 keypoints of a face.

landmarks

avatar

For example, a number 27 and number 29 are the sides of the mouth.

File: /package_face_tracker/utils/modelBusiness.js

// index of the track points of the face
const trackPointA = {
    // index of a landmark
    id: 27,
    // X coordinate
    x: 155.69898111309, // the width of the face image is 375
};
const trackPointB = {
    // index of a landmark
    id: 29,
    // X coordinate
    x: 216.53075265284997, // the width of the face image is 375
};

Known Issues

The AR demo is very slow on iOS WeChat.

BSD 3-Clause License Copyright (c) 2021, AR Fashion All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

简介

暂无描述 展开 收起
README
BSD-3-Clause
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/gzwzj/WeChat-MiniProgram-WebAR.git
git@gitee.com:gzwzj/WeChat-MiniProgram-WebAR.git
gzwzj
WeChat-MiniProgram-WebAR
WeChat-MiniProgram-WebAR
master

搜索帮助