当前位置:网站首页>Write a rotation verification code annotation gadget with aardio
Write a rotation verification code annotation gadget with aardio
2022-07-06 21:53:00 【Qwertyuiop2016】
demand
Recently, I want to train the model of rotary verification code recognition . Tagging data is a meaningless and time-consuming job , And there is no handy annotation tool for the rotation verification code . No, then write one by yourself .
The articles you see on the Internet are generated 360 An angle picture , Find the one with positive direction . Generate 360 Pictures from different angles are time-consuming , A picture takes about a minute or two , And then in 360 It's troublesome to choose one of the pictures .
Start writing code
Rotation effect
I haven't seen it for a long time aardio What library can rotate pictures , Just when I was going to use aardio call Python when , Suddenly see in HTML Rotating pictures in only need of img Add a... To the label style="transform: rotate(0deg);"
Among them 0 It's the angle of rotation , Support negative numbers
That is to say, I only need to use the function of rotating pictures html Can achieve , I just need to control 0deg Number in , You can control the rotation angle of the picture .
// Screenshot Remote debugging
import win.ui;
import web.view;
/*DSG{
{*/
var mainForm = win.form(text=" Rotate the verification code annotation ";right=468;bottom=605;acceptfiles=1;bgcolor=16777215;border="thin")
mainForm.add()
/*}}*/
var wb = web.view(mainForm,,0);
wb.go('/res/1.html')
mainForm.show();
return win.loopMessage();
1.html Code for
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<style type="text/css"> .vcode-spin-faceboder {
position: relative; overflow: hidden; width: 350px; height: 350px; margin: 28px auto 24px; border: 0; -webkit-background-size: 100% 100%; background-size: 100% 100% } .vcode-spin-img {
position: relative; z-index: 999; width: 100%; height: 100%; pointer-events: none; -webkit-border-radius: 50%; border-radius: 50% } .next {
width: 50px; height: 15px; background-color: rgb(250,0,255) } </style>
<script type="text/javascript"> </script>
</head>
<body style="margin:50px">
<div class="vcode-spin-faceboder">
<img class="vcode-spin-img" src="1.jpg" style="transform: rotate(0deg);">
<button id="next" class="next"></button>
</div>
</body>
</html>
effect :
modify html Tag attributes
// 180 It's the angle of rotation
var js = string.format(`this.setAttribute("style", "transform: rotate(%ddeg);");`, 180);
// 100 by timeout Time , Unit millisecond , The front is css Selectors
wb.waitEle(".vcode-spin-img", js, 100);
If change to js Writing :
var inp = document.getElementsByClassName("vcode-spin-img");
inp.setAttribute("type", "transform: rotate(180deg);");
Add a slider
I want to control the rotation angle of the picture by sliding the position of the slider . First, select the tracking bar in the interface control , Scale words 0-359, I changed it to (-179-180). However, the library code says that negative numbers cannot be used , I tried negative numbers, but it's ok , Just ignore him
// Specify the maximum scale of the slider
mainForm.trackbar.max=359;
// Specify the minimum scale of the slider
mainForm.trackbar.min=0;
// Specify the current scale of the slider
mainForm.trackbar.pos=0;
Add slider logic
effect :
mainForm.trackbar.onnotify = function(id,code,ptr){
if(code==0xFFFFFFF4){
var js = string.format(`this.setAttribute("style", "transform: rotate(%ddeg);");`, mainForm.trackbar.pos);
wb.waitEle(".vcode-spin-img", js, 100);
}
}
preservation
The rotation is correct , To save the rotated picture . At present, I think of two methods , The first direct screenshot of the current software interface , It will cut in the buttons . Just deal with it later . Because the size of the interface is constant , You only need to cut the specified part of the graph
var picture = gdip.snap(mainForm.hwnd);
// filename It's the file path ,100 Is the quality of documents (0-100), Targeted only jpg Format
picture.save(filename,100);
The second is a screenshot of a web page , Because the interface is browser based . So you can also support devtools protocol agreement
First step : Open remote control port
var ws = wb.openRemoteDebugging()
ws.Runtime.enable();
The second step : Get the location of the image control on the web page (x, y and width, height). use js It's OK to , And then execute js Get the return value . Not cut img label , But cut off the outer layer div. Because the outer layer div It's fixed size . section img The size will change
// stay aardio Middle quotation marks can be wrapped
js = '(function(){
var a = document.querySelector(".vcode-spin-faceboder").getBoundingClientRect();
return a.toJSON();
})()'
perform js
ws.Runtime.evaluate(expression=js, awaitPromise=true,returnByValue=true).end = function(result, err){
console.dump(result);
var clip = {
scale=1;x=result.left+pageX;y=result.top+pageY;width=result.width;height=result.height};
}
pageX and pageY obtain ( I don't know why I want to add this , I saw it pyppeteer Add this to the source code ), The actual value obtained is also 0,0 So it doesn't matter whether you add it or not
var pageX,pageY;
ws.Page.getLayoutMetrics().end = function(result, err){
pageX = result[["layoutViewport"]].pageX
pageY = result[["layoutViewport"]].pageY
}
For the screenshot of the control , In fact, it is a full screen shot , Then give me a x,y Widen, heighten and cut
ws.Page.captureScreenshot(clip=clip).end = function(result,err){
if(result[["data"]]){
var bin = crypt.decodeBin(result[["data"]]);
string.save("\1.PNG", bin )
}
}
Add some buttons
Final effect :
Instructions
On the right of the slider 0 Express , The angle of rotation ( The current scale of the slider ). This control is an edit box , You can change this angle , Then click rotate to rotate the specified angle
Below 1 Indicates the number of pictures in the currently specified folder , You need to press the select button to select a folder with rotating pictures , Forward and backward are to select the previous picture and the next picture of the folder ( Cycle )
The Save button is to save the marked pictures to the folder ( Cannot specify folder , Is to create a in the current folder result, The file named 1.jpg,1 Which picture is it )
I always want to use aardio Write some tools , Later, I will talk about how to use aardio pack Python.
Complete code and software
https://github.com/kanadeblisst/rotate_qrcode_label
边栏推荐
- Dialogue with Jia Yangqing, vice president of Alibaba: pursuing a big model is not a bad thing
- Uni app app half screen continuous code scanning
- Binary tree node at the longest distance
- 记一次清理挖矿病毒的过程
- C# 如何在dataGridView里设置两个列comboboxcolumn绑定级联事件的一个二级联动效果
- Set up a time server
- 缓存更新策略概览(Caching Strategies Overview)
- Univariate cubic equation - relationship between root and coefficient
- 爬虫实战(五):爬豆瓣top250
- [Li Kou brush questions] 32 Longest valid bracket
猜你喜欢
Why rdd/dataset is needed in spark
PostgreSQL modifies the password of the database user
50 commonly used numpy function explanations, parameters and usage examples
Yyds dry goods inventory C language recursive implementation of Hanoi Tower
uni-app App端半屏连续扫码
【MySQL】Online DDL详解
Reptile practice (V): climbing watercress top250
Vit paper details
Leetcode topic [array] -118 Yang Hui triangle
guava:Collections. The collection created by unmodifiablexxx is not immutable
随机推荐
Guava: use of multiset
Binary tree node at the longest distance
50个常用的Numpy函数解释,参数和使用示例
[Li Kou brushing questions] one dimensional dynamic planning record (53 change exchanges, 300 longest increasing subsequence, 53 largest subarray and)
强化学习-学习笔记5 | AlphaGo
Aggregate function with key in spark
LeetCode学习记录(从新手村出发之杀不出新手村)----1
在最长的距离二叉树结点
PostgreSQL install GIS plug-in create extension PostGIS_ topology
c语言char, wchar_t, char16_t, char32_t和字符集的关系
NPM run dev start project error document is not defined
【力扣刷题】一维动态规划记录(53零钱兑换、300最长递增子序列、53最大子数组和)
What about the spectrogram
50 commonly used numpy function explanations, parameters and usage examples
Digital transformation takes the lead to resume production and work, and online and offline full integration rebuilds business logic
Redistemplate common collection instructions opsforhash (IV)
互联网快讯:吉利正式收购魅族;胰岛素集采在31省全面落地
From campus to Tencent work for a year of those stumbles!
Z function (extended KMP)
[Chongqing Guangdong education] Information Literacy of Sichuan Normal University: a new engine for efficiency improvement and lifelong learning reference materials