又一个Perl的程序(原创)

该博客展示了一段Perl代码,用于创建一个图形界面,让用户输入源文件路径和目标文件路径。代码会检查路径有效性,获取源文件夹中的JPG文件,并执行特定命令处理这些文件,同时将处理信息输出到界面文本框中。

#!/usr/bin/perl -W

use Tk;
use Tk::PathEntry;
use Tk::message;
use DirHandle;
use Cwd;

my $srcPath = cwd();
my $dstPath = cwd();

 $mw = MainWindow -> new(-title => "Auto Red Eye Removal");

 $srcFrame = $mw -> Frame(-width => 600, -height => 10);
 $srcFrame -> Label(-width => 10) -> pack(-side => 'left');
 $srcFrame -> Label(-text => "源文件路径:") -> pack(-side => 'left');
 $srcEntry = $srcFrame -> PathEntry(-textvariable => /$srcPath, -width => 70);
 $srcFrame -> Label(-width => 10) -> pack(-side => 'right');
 $srcEntry -> pack(-side => 'right');

 $dstFrame = $mw -> Frame(-width => 600, -height => 10);
 $dstFrame -> Label(-width => 10) -> pack(-side => 'left');
 $dstFrame -> Label(-text => "目标文件路径:") -> pack(-side => 'left');
 $dstEntry = $dstFrame -> PathEntry(-textvariable => /$dstPath, , -width => 70);
 $dstFrame -> Label(-width => 10) -> pack(-side => 'right');
 $dstEntry -> pack(-side => 'right');

 $cmdFrame = $mw -> Frame(-width => 600, -height => 35);
 $cmdFrame -> Label(-width => 25) -> pack(-fill => 'x', -side => 'left');
 $cmdFrame -> Label(-width => 25) -> pack(-fill => 'x', -side => 'right');
 $runButton = $cmdFrame -> Button(-text => "Run", -height => 1, -width => 8,
     -command => /&Run);
 $exitButton = $cmdFrame -> Button(-text => "Exit", -height => 1, -width => 8,
     -command => sub{ exit }, -default => 'active');
 $runButton -> pack(-side => 'left');
 $exitButton -> pack(-side => 'right');

 $outputFrame = $mw -> Frame(-width => 600, -height => 400);
 $outputText = $outputFrame -> Text(-width => 80, -height => 25, -wrap => 'word',
                 -background => 'gray', -font => 'normal');
 $outputText -> pack(-side => 'left', -fill => 'y');

 $scrollBar = $outputFrame -> Scrollbar(-command => ['yview' => $outputText]);
 $outputText -> configure(-yscrollcommand => ['set' => $scrollBar]);
 $scrollBar -> pack(-side => 'right', -fill => 'y');

 $srcFrame -> pack(-side => 'top', -fill => 'both');
 $dstFrame -> pack(-side => 'top', -fill => 'both');
 $cmdFrame -> pack(-side => 'top', -fill => 'both');
 $outputFrame -> pack(-side => 'top');
 $mw -> resizable(0, 0);

MainLoop;

sub Run() {
  my $src_path = $srcPath."/";
  my $dst_path = $dstPath."/";

  if($src_path eq '' || $dst_path eq '') {
    $mw -> messageBox(-type => 'OK', -title => "Error",
       -message => "请输入目标文件路径或源文件路径!!");
    die;
  }
  elsif ($src_path eq ' ' || $dst_path eq ' ') {
    $mw -> messageBox(-type => 'OK', -title => "Error",
       -message => "请输入目标文件路径或源文件路径!!");
    die;
  }
 
  $src_path = &Trim($src_path);
  $dst_path = &Trim($dst_path);
 
  my @arrayFiles;
  if(&isFolder($src_path)) {
   @arrayFiles = &getJPGFiles($src_path);
  }
  else {
  $mw -> messageBox(-type => 'OK', -title => "Error",
     -message => "源文件夹路径不存在,请输入正确的文件夹路径!");
  die;
  }
 
  if(&isFolder($dst_path)) {
   
  }
  else {
   $mw -> messageBox(-type => 'OK', -title => "Error",
     -message => "目标文件夹路径不存在,请输入正确的文件夹路径!");
  die;
  }
 
  foreach my $file (@arrayFiles) {
   $outputText -> insert('end', "Source file is: ".$src_path.$file."/n".
               "Dest file is: ".$dst_path.$file."/n");
  $outputText -> insert('end', "Current redeye is detected: ");
  
   $command = "demo $src_path"."$file "."$dst_path"."$file 1 1 0";
   eval {
    open(FD, "$command 2>&1 |");
    while($line = <FD>) {
     $outputText -> insert('end', $line);
    }
    $outputText -> insert('end', "/n");
   }
 }
 
  close(FD);
  die;
}

sub Trim() {
 $tmp = $_[0];
 
 for($tmp) {
  s/^/s+//;
  s//s+$//;
 }
 return $tmp;
}

sub getJPGFiles() {
 my $tmppath = $_[0];
 
 $tmppath = $tmppath."/";
 my $dh = new DirHandle("$tmppath");
 
 @files = DirHandle::read($dh);
 undef $dh;
 
 @files = sort(@files);
 shift(@files);
 shift(@files);
 
 if(@files == 0) {
  $mw -> messageBox(-type => 'OK', -title => "Error",
     -message => "当前文件夹为空,请检查!");
  die;
 }
 
 my @tempfiles;

 foreach my $f (@files) {
  if($f =~ /(.jpg)$/ || $f =~ /(.JPG)$/) {
   push @tempfiles, $f;
  }
 }
 
 if(@tempfiles == 0) {
  $mw -> messageBox(-type => 'OK', -title => "Error",
     -message => "当前文件夹中不存在jpg文件!");
  die;
 }
 
 @files = @tempfiles;
 return @files;
}

sub isFolder() {
 $tmp = $_[0];
 
 my $dh = new DirHandle("$tmp");
 
 if(!(defined $dh)) {
  return 0;
 }
 
 undef $dh;
 return 1;
}

内容概要:本文介绍了ENVI Deep Learning V1.0的操作教程,重点讲解了如何利用ENVI软件进行深度学习模型的训练与应用,以实现遥感图像中特定目标(如集装箱)的自动提取。教程涵盖了从数据准备、标签图像创建、模型初始化与训练,到执行分类及结果优化的完整流程,并介绍了精度评价与通过ENVI Modeler实现一键化建模的方法。系统基于TensorFlow框架,采用ENVINet5(U-Net变体)架构,支持通过点、线、面ROI或分类图生成标签数据,适用于多/高光谱影像的单一类别特征提取。; 适合人群:具备遥感图像处理基础,熟悉ENVI软件操作,从事地理信息、测绘、环境监测等相关领域的技术人员或研究人员,尤其是希望将深度学习技术应用于遥感目标识别的初学者与实践者。; 使用场景及目标:①在遥感影像中自动识别和提取特定地物目标(如车辆、建筑、道路、集装箱等);②掌握ENVI环境下深度学习模型的训练流程与关键参数设置(如Patch Size、Epochs、Class Weight等);③通过模型调优与结果反馈提升分类精度,实现高效自动化信息提取。; 阅读建议:建议结合实际遥感项目边学边练,重点关注标签数据制作、模型参数配置与结果后处理环节,充分利用ENVI Modeler进行自动化建模与参数优化,同时注意软硬件环境(特别是NVIDIA GPU)的配置要求以保障训练效率。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值