Jcrop图像裁剪

使用jQuery Jcrop插件轻松实现图像裁剪功能 在现代Web开发中,图像处理是一个经常遇到的需求,特别是在用户界面设计中,图像裁剪功能能够大幅增强用户体验。在众多可用的JavaScript库中,jQuery Jcrop插件因其简便性、灵活性和强大的功能脱颖而出。本章将介绍jQuery Jcrop插件的基础知识,包括它的主要功能以及如何集成到您的项目中,为后续章节深入使用和优化奠定基础。Jcrop的主要功能:Jcrop提供了简洁的API和直观的用户交互方式,允许开发者轻松添加图像选择功能。 阅读详情

一、Jcrop简介

Jquey Jcrop是一款功能强大的图像裁剪插件,结合服务端的处理可实现图片裁剪,改变等功能。
具有如下特点:
显示图像或块对象
支持图片的最大,最小值的设置
有交互性的API,包含动画
提供CSS样式的定义
支持IOS,android等平台

二、使用方法

1.载入 CSS 文件
<link type="text/css" rel="stylesheet" href="../css/jquery.Jcrop.css" />

2.载入 JavaScript 文件

<script  type="text/javascript" src="jquery.js"></script> 
<script type="text/javascript" src="../js/jquery.Jcrop.js"></script>    

3.给 IMG 标签加上 ID

<div class="Preview-pic" id="previewIcon">
   <img id="imgCrop" class="imgCrop" name="imgCrop" 
    width="300" height="300" border="0" src=""/>    
  </div>

4.调用 Jcrop

jcrop_api=$.Jcrop('#imgCrop',{
        aspectRatio: 1,
        onChange: showCoords, // 选框改变时的事件
        onSelect: showCoords // 选框选定时的事件
    });

三、使用实例

1.下载Jcop的依赖文件,下载地址如下:
http://deepliquid.com/content/Jcrop.html,将css和js文件引入项目中 。

2.页面定义

<header class="head-revision-top clearfix">
 <h4 class="fl" id="sysField">
    <a href="">系统头像</a>
  </h4>
  <p class="fr head-revision-file">
  <input class="head-revision-input" type="file" 
        accept="image/*" name="uploadFile" id="uploadFile"      onchange="checkImgType(this);" />
 </p>
</header>
<div class="head-revision mt20 clearfix" id="uploadIcon">
  <div class="Preview-pic" id="previewIcon">
    <img id="imgCrop" class="imgCrop" name="imgCrop" 
        width="300" height="300" border="0" src=""/>    

  </div>

3.js实现

 var firstFlag = false,count=0;
var jcrop_api, boundx, boundy;
$(function(){
    $('#userIconBtn').click(function() {
        var x = $("#x").val();
        var y = $("#y").val();
        var w = $("#w").val();
        var h = $("#h").val();
        if (w == 0 || h == 0) {
            alert("您还没有选择图片的剪切区域,不能进行剪切图片!");
            return;
        }else{
            $.ajax({
                url: '',
                data: $('#uploadIconForm').serialize(),
                type: "POST",
                beforeSend: function()
                {  
                },
                success: function()
                {
                    // 提交成功,刷新页面
                    //location.reload(true);
                    window.location.href="";
                }
            });

        }
    });
});

/**检查图片上传类型*/          
 function checkImgType(obj){
 //更换头像销毁原有的jcrop   
 if(count>=1){
    firstFlag=false;
    jcrop_api.destroy();
 }
  var uploadFile = '';    
  //获取图片的全路径   
  var imgFilePath = getImgFullPath(obj);        
  var endIndex = imgFilePath.lastIndexOf("\\");   
  var lastIndex = imgFilePath.length-endIndex-1;   
  if (endIndex != -1)   
     uploadFile= imgFilePath.substr(endIndex+1,lastIndex);   
  else  
     uploadFile = imgFilePath;        

  var tag = true;               
  endIndex = imgFilePath.lastIndexOf(".");              
  if (endIndex == -1)    
    tag = false;   

  var ImgName = imgFilePath.substr(endIndex+1,lastIndex);   
  ImgName = ImgName.toUpperCase();           

  if (ImgName !="GIF" && ImgName !="JPG" && ImgName !="PNG" && ImgName !="BMP"){    
      tag=false;   
  }
  if (!tag) {   
      alert("上传图片的文件类型必须为: *.gif,*.jpg,*.png,*.bmp,请重新选择!")   
      Upload.clear(obj);                        
      return false;   
  }else{
        count++;
        $.ajaxFileUpload({  
                url: "user!uploadFile",            //需要链接到服务器地址  
                secureuri:false,  
                fileElementId:"uploadFile",                  //文件选择框的id属性  
                dataType: "json",                            //服务器返回的格式,可以是json  
                success: function(data){
                    if(data.resultCode=1){
                        $("#imgCrop").attr("src",data.resultInfo);
                        $("#imgCrop").attr("width",data.width);
                        $("#imgCrop").attr("height",data.height);
                        $("#width").val(data.width);
                        $("#height").val(data.height);
                        $("#imgFileExt").val(data.imgFileExt);
                        $("#oldImgPath").val(data.oldImgPath);
                        jcrop_api=$.Jcrop('#imgCrop',{
                            aspectRatio: 1,
                            onChange: showCoords, // 选框改变时的事件
                            onSelect: showCoords // 选框选定时的事件
                        });
                    }else{
                        alert("系统连接有误,请重新上传或连接管理员");
                    }
                    jcrop_api.enable();
                    jcrop_api.setImage(data.resultInfo);
                    jcrop_api.animateTo([0,0,200,200]);
                    jcrop_api.setOptions({
                                 allowResize:true,
                                 allowSelect: false,
                                 allowMove:true
                                 });
                    //获取图片的实际尺寸          
                    var bounds=jcrop_api.getBounds();
                    boundx=bounds[0];
                    boundy=bounds[1];
                } 
            });  
        }
}     
function getImgFullPath(obj) {   
    if (obj) {     
       //ie     
       if (window.navigator.userAgent.indexOf("MSIE") >= 1) {     
           obj.select();     
           return document.selection.createRange().text;     
       }     
       //firefox     
       else if (window.navigator.userAgent.indexOf("Firefox") >= 1) {     
           if (obj.files) {     
               return obj.files.item(0).getAsDataURL();     
           }     
           return obj.value;     
       }            
       return obj.value;     
   }     
} 
function showCoords(c) {
    $('#x').val(c.x);
    $('#y').val(c.y);
    $('#x2').val(c.x2);
    $('#y2').val(c.y2);
    $('#w').val(c.w);
    $('#h').val(c.h);
    if(!firstFlag){
        exchange();
    }
    showPreview(c);

}       
function exchange(){
    firstFlag = true;
    $('#preview').attr("src", $('#imgCrop').attr("src"));

}
function showPreview(coords) {
    if (parseInt(coords.w) > 0) {
        var rx = 200 / coords.w;
        var ry = 200 / coords.h;
        $('#preview').css({
            width:Math.round(200/ coords.w * boundx) + 'px',  //200 为预览div的宽和高
            height:Math.round(200/ coords.h * boundy)+ 'px', 
            marginLeft : '-' + Math.round(rx * coords.x) + 'px',
            marginTop : '-' + Math.round(ry * coords.y) + 'px'
        });
    }
}

4.服务器处理(java)

public String uploadFile() {
    int result = Constant.RET_OK;
    String resultUrl = "";
    String imgUploadPath = "";
    // 图片初始化高度与宽度
    String width = null;
    String height = null;
    int imgWidth = 0;
    int imgHeight = 0;
    SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
    String userWebAppPath = getWebAppPath();
    /** 检查是否有图片上传文件夹 */
    FileUtil.checkImageDir(userWebAppPath);
    try {
        UserPOJO userSession = (UserPOJO) getSession(Constant.USERLOGINSESSION);
        if (null == userSession) {
            result = Constant.ISSESSIONERROR;
        }
        // 指定图片宽度和高度
        width = getRequest().getParameter("width");
        if (null == width || "".equals(width)) {
            width = "300";
        }
        height = getRequest().getParameter("height");
        if (null == height || "".equals(height)) {
            height = "300";
        }
        imgWidth = Integer.parseInt(width);
        imgHeight = Integer.parseInt(height);
        List<File> files = getUploadFile();
        if (files != null && files.size() > 0) {
            for (int i = 0; i < files.size(); i++) {
                File userFile = files.get(i);
                try {
                    String filePath = FileUtil.saveLocalImg(userFile, userWebAppPath + "\\"
                            + getUploadFileFileName().get(0));
                    BufferedImage src = ImageIO.read(new File(filePath)); // 读入文件
                    int imgSrcWidth = src.getWidth(); // 得到源图宽
                    int imgSrcHeight = src.getHeight(); // 得到源图长
                    // 重新指定大小
                    if (imgSrcWidth >= imgSrcHeight) {
                        imgWidth = imgSrcWidth > 300 ? 300 : imgSrcWidth;
                        imgHeight = (int) (imgWidth * (float) imgSrcHeight / (float) imgSrcWidth);
                        imgHeight = imgHeight < 200 ? 200 : imgHeight;
                    } else {
                        imgHeight = imgSrcHeight > 300 ? 300 : imgSrcHeight;
                        imgWidth = (int) (imgHeight * (float) imgSrcWidth / (float) imgSrcHeight);
                        imgWidth = imgWidth < 200 ? 200 : imgWidth;
                    }
                    // 按照图片的设置大小生成
                    ImageCut.scale(src, userFile, imgWidth, imgHeight);
                    log.info("创建" + imgWidth + "*" + imgHeight + "图片成功");
                    // 上传图片到图片服务器并获得访问地址
                    FileInputStream fis = new FileInputStream(userFile);
                    byte[] fileBytes = new byte[fis.available()];
                    fis.read(fileBytes);
                    fis.close();
                    resultUrl = FileUtil.getImageUrl(FileUtil.getExtName(this.getUploadFileFileName().get(0)),
                            fileBytes);
                    // 将远程服务器得到的文件保存到该服务器
                    String newFileName = df.format(new Date()) + "_" + new Random().nextInt(1000) + "."
                            + FileUtil.getExtName(this.getUploadFileFileName().get(0));
                    imgUploadPath = IMGROOT + newFileName;
                    FileUtil.saveImageToLocal(resultUrl, userWebAppPath + newFileName);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        result = Constant.SYSTEM_ERROR;
    }
    Map<Object, Object> infoMap = new HashMap<Object, Object>();
    infoMap.put(Constant.RESULT_CODE_KEY, result);
    infoMap.put(Constant.RESULT_INFO, resultUrl);
    infoMap.put("width", imgWidth);
    infoMap.put("height", imgHeight);
    infoMap.put("oldImgPath", imgUploadPath);
    infoMap.put("imgFileExt", FileUtil.getExtName(this.getUploadFileFileName().get(0)));
    JSONObject json = JSONObject.fromObject(infoMap);
    writeJSON(json.toString());
    return null;
}

四、API接口及参数说明

http://code.ciaoca.com/jquery/jcrop/    

五、实现效果

这里写图片描述

Jcrop-0.9.12.zip 效果https://blog.csdn.net/qq_29099209/article/details/85006728 立即下载

相关推荐

JCOP Eclipse javacard 插件

JCOP Eclipse javacard 插件

裁切图片插件jcrop的简单使用(插件化)

因为之前好几个项目和页面都要用到图片裁切功能,我就把图片裁切插件jcrop稍稍封装了一下,以达到任一个img标签,只需要非常简单的js代码即可变成可裁切的img框;jcrop官网:http://deepliquid.com/content/Jcrop.html简述 将页面的某个标签初始化成有裁切框样式的图片,并把裁切框信息发送给后台裁切;使用 1、 依次引入jquery.Jcr

哈哈哈哈哈哈 936

OCC WebGL案例编译实战:从FreeType配置到静态库生成

本文详细记录了将OCC(Open CASCADE Technology)3D图形库编译为WebAssembly(Wasm)并在浏览器中通过WebGL渲染的实战过程。重点解决了FreeType库的交叉编译配置、OCC核心库的裁剪与静态库生成,以及WebGL样例项目的CMake改造等关键步骤,为开发者提供了从环境搭建到最终集成的完整指南。

weixin_28831461的博客 320

jquery插件jcrop的初步认识与用法

最近在写项目的过程中,需要用到图像裁切上传,所以接触了插件jcrop。这个插件的裁切功能主要是获取裁切图片后的x坐标,y坐标与裁切图片的宽度和高度。该插件运行后,dom格式如下 关于该插件的源码,以及源码中的中文注释部分已发布到github 源码解析 这里说一下主要用法 首先需要引入jquery库和jcrop插件<script type="text/javascript" src="src/

charlene0824的博客 1280

hpm6750evk2开发板(四)TCP回送(1000M网口)

再接下来我们修改代码,先找到配置网速的地方,肯定是在enet的初始化函数里面,我们一个函数一个函数找,也可以用单步调试一步一步找,结果发现是在enet_init函数里面调用的rtl8211_basic_mode_default_config函数配置网速的,我们把enet_phy_port_speed_100mbps改为enet_phy_port_speed_1000mbps,重新编译运行试试。首先我们复制一份lwip_tcpecho代码,重命名为lwip_tcpecho_RGMII,如下图所示。

Silas1750的博客 928

地震勘探原理---地震预处理

3.1 为什么说要对数据进行振幅补偿?具体来说,地震波在传播过程中会遇到各种各样的地质条件,例如不同的岩层、土壤、水层等,这些介质的密度、速度等特性不同,因而对地震波的能量消耗也有所不同。在传播距离较远的情况下,能量损失可能会导致接收到的地震信号振幅变小。相反,在传播距离较近的情况下,能量损失可能较小,导致接收到的地震信号振幅变大。如果不对数据进行振幅补偿,这种振幅不均衡会导致地震数据分析和解释的误差和不确定性增加,可能产生错误的结论。

DARRENANJIAN的博客 3288

BitCPM4-CANN-8B技术报告解读:Megatron-LM框架下的Ascend NPU优化指南

BitCPM4-CANN-8B是首个在华为昇腾Ascend NPU上实现端到端1.58位(三元)大语言模型训练的开源系统。这个基于Megatron-LM框架优化的AI模型在保持95.7%性能的同时,实现了约6倍的内存压缩,为国产AI芯片生态带来了革命性的突破!🚀 ## 什么是BitCPM4-CANN-8B?🤔 BitCPM4-CANN-8B是由OpenBMB团队开发的创新型大语言模型,它将

gitblog_00006的博客 715

5.1 滑模控制(SMC)及其改进

本文系统阐述了滑模控制(SMC)的基本原理及其在永磁同步电机(PMSM)控制系统中的应用。首先介绍了滑模控制的核心思想,包括滑模面设计和不连续控制律,其强鲁棒性使其在电机控制领域得到广泛应用。其次分析了SMC在PMSM速度控制器和无位置传感器观测器中的具体实现方案。重点探讨了SMC固有的抖振问题,详细比较了边界层法、高阶滑模和自适应方法等多种改进策略的优缺点。最后指出改进SMC的研究趋势是多种策略的融合应用,如自适应高阶滑模等,以在保持鲁棒性的同时有效抑制抖振。

技术工作者 1460

【亲测免费】 Jcrop 图像裁剪插件使用教程

Jcrop 是一个快速且易于使用的 JavaScript 图像裁剪插件,适用于 Web 应用程序。它结合了 jQuery 插件的易用性和强大的跨平台 DHTML 裁剪引擎,能够忠实地模拟桌面图形应用程序的裁剪功能。 ### 主要特性 - **跨平台兼容性**: 支持 Firefox 2+、Safari 3+、Opera 9.5+、Google Chrome 0.2+ 和 Internet Ex...

gitblog_00599的博客 600

如何创建 SAP ABAP CDS View 的 Association

所以本文我们虽然学习了如何创建 SAP CDS View 的 association,知道了 association 是用来在 CDS View 里将两张数据库表关联起来,但根本不知道怎么使用这个 association. 而且从 association 的写法来看,似乎和本教程之前介绍 inner join,left join 这些数据库表的连接操作没什么区别,都是根据两张表的 carrid 和 connid 字段相同进行的连接。只看到了我们在 CDS View 源代码实现里,放出来的四个字段。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 918

AutoSAR EcuM系列01- EcuM模块的功能概述和变体类型

在【ECU的软硬件架构】文章中我们了解ECU的功能和组成,那么ECU具体是怎么启动的呢?我们知道,AutoSAR标准架构有三层,即APPL应用层、RTE层和BSW层。而这些层又被进一步划分为更多单独的组件,如BSW层可能有80多个组件。在ECU启动时,这些组件必须相互交互,有时也必须以某种顺序交互。这些组件的启动顺序由ECU管理器模块或EcuM处理。EcuM负责整个ECU的初始化和去初始化,包括对一些系统模块如。......

1771

使用Jcrop(jQuery)在运行时裁剪图像

Today we use jcrop api. During browsing the Internet I noticed one new good plugin which we can use to work with images. This is JCrop plugin, it can help us to perform different effect with images (a...

cuken7684698822的博客 527

基于STM32设计的智能水产养殖系统(华为云IOT)(152)

当前设计的智能水产养殖系统主控芯片采用STM32F103RCT6,可以实现对水位、水温、水混浊度和PH值等参数的监测和控制,并且支持定时投喂功能。通过连接华为云物联网平台,将传感器数据上传到服务器,并通过Qt设计的Android手机APP来获取设备上传的数据,从而实现对养殖环境的远程监测和控制。

8842

使用 jQuery Jcrop 实现图像裁剪

一、使用方法: 代码: // 载入CSS文件 <link rel="stylesheet" href="css/jquery.Jcrop.css"> // 载入JavaScript文件 <script src="js/jquery.js"></script> <script src="js/jquery.Jcrop.js"></scr...

dev_zyx的博客 1539

华为OD机试 - 仓库查询 - 树状数组(Java 新系统 200分)

华为OD机试 新系统 题库疯狂收录中,刷题。

学Java,找哪吒 172

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

jQuery Jcrop 图像裁剪

Jcrop 是一个功能强大的 jQuery 图像裁剪插件,结合后端程序(例如:PHP)可以快速的实现图片裁剪的功能。 版本:jQuery v1.5.1+jQuery Jcrop v0.9.12 查看 Demo下载 jQuery Jcrop v0.9.12官网下载提交问题 / Bug / 建议 文档目录 使用方法参数说明 API 接口相关信息

小飞侠的博客 829

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

jQuery的图像裁剪插件Jcrop的简单使用

目前做的这个项目中要用到用户头像功能,领导说最好是做成用户上传一个图片后可以用图像裁剪的方法自己选择头像。同事推荐了Jcrop这个插件,到它的官方站点http://deepliquid.com/content/Jcrop.html下载了最新版的压缩包,压缩包中包括了Jcrop的几个demo文件,关键的Jcrop.js文件和jQuery.Jcrop.css文件。基本上来说参照它的几个dem...

weixin_30722589的博客 181

InTheHand.Net.Personal+BlueTooth4,蓝牙开发

项目中有蓝牙开发的必备dll,现在网上相关的文档博客不少,有的说的多有的说少,但是却很少有这两个dll,分享一下。

vb 6.0并口开发操作实例

vb6并口开发,简体中文,试例内有inpout32.dll动态链接库

Jcrop是一个功能强大的图像裁剪引擎

Jcrop是一个功能强大的图像裁剪引擎jQuery的。 它的设计使开发人员可以很容易地直接集成了先进的图像裁剪功能集成到任何基于Web的应用程序在不牺牲动力和灵活性(或编码,测试和调试的星期)。Jcrop还设有干净,组织良好的代码,在大多数现代的web浏览器效果很好。 在你需要加载必要文件的页面 这包括: jQuery库 Jcrop的Javascript Jcrop CS

hins 5203

图像裁剪Jquery.Jcrop开发记录

本文记录一次图像裁剪工具Jquery.Jcrop的备注信息。 1.何为图像裁剪 图像裁剪如下图所示: 图像裁剪常用与截取头像、logo等等。 2.相关技术文档 jQuery Jcrop 图像裁剪开发库:有很详细的Demo、资源包、参数说明、API等等。...

韩超的博客 (hanchao5272) 625
上一篇: swiper图片轮播插件
下一篇: jquery实现页面无限滚动插件
greekw
博客等级 码龄16年 35粉丝 103原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值