You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

detection.js 87 kB

3 years ago
3 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938
  1. //
  2. /**
  3. * @author zhaiyunpeng
  4. * @copyright 2019
  5. * javascript for person and vehicle detection
  6. */
  7. var regions;
  8. var img=new Image();
  9. var imginfo = {};
  10. var ip = getIp();
  11. var token = getSessionStorageMessage("token");
  12. var userType = getSessionStorageMessage("userType");
  13. console.log("token=" + token);
  14. var loadFinished=false; //判断是否加载完成,防止上下张快捷键过快,导致保存冲刷掉原有数据,保存空数据
  15. var currentImage=true;
  16. if(userType == 2){
  17. $('#title_id').text("通用图片审核");
  18. }
  19. function getCookieOrMessage(key){
  20. var value = getCookie(key);
  21. return value;
  22. }
  23. function getSessionStorageMessage(key){
  24. var value = sessionStorage.getItem(key);
  25. if(isEmpty(value)){
  26. return localStorage.getItem(key);
  27. }
  28. return value;
  29. }
  30. //获取元素绝对位置 获取鼠标坐标
  31. function getElementLeft(element){
  32. var actualLeft = element.offsetLeft;
  33. var current = element.offsetParent;
  34. while (current !==null){
  35. actualLeft += (current.offsetLeft+current.clientLeft);
  36. current = current.offsetParent;
  37. }
  38. return actualLeft;
  39. }
  40. function getElementTop(element){
  41. var actualTop = element.offsetTop;
  42. var current = element.offsetParent;
  43. while (current !== null){
  44. actualTop += (current.offsetTop+current.clientTop);
  45. current = current.offsetParent;
  46. }
  47. return actualTop;
  48. }
  49. // canvas 矩形框集合
  50. //by yunpeng zhai
  51. //变量定义//变量重置
  52. //
  53. var verifyMap = {"1":"大小不合格","2":"颜色不合格","3":"其它不合格"};
  54. var label_task = getSessionStorageMessage("label_task");
  55. var label_task_status = getSessionStorageMessage("label_task_status"); //1表示审核
  56. console.log("label_task=" + label_task);
  57. var label_task_info;
  58. var labeltastresult;
  59. var rects=[];
  60. var masks=[];
  61. var pointShapes =[];
  62. var copyrects;//复制变量
  63. var copymasks;//复制使用的变量
  64. var copyPointShapes;
  65. var undoShape;
  66. var color_dict = {"rect":"#13c90c","car":"#0099CC", "person":"#FF99CC","point":"#00cc00","pointselected":"red"};
  67. var color_person = {"0":"#13c90c","1":"#fc0707","2":"#FF99CC","3":"#fceb07"};
  68. var color_all={"0":"#13c90c","1":"#fc0707","2":"#FF99CC","3":"#fceb07","4":"#FF33FF","5":"#666600","6":"#4B0082","7":"#B8860B","8": "#000000","9":"#800000","10": "#FF00FF","11":"#8B4513","12":" #0000CD","13":" #008B8B","14":"#708090","15": "#00FFFF","16":"#FF00FF","17":"#9370DB","18":"#7CFC00","19":"#F08080","20":"#C71585"};
  69. var SelectedRect;
  70. var SelectedpointId;
  71. var Selectedmask;
  72. var SelectedPointShape;
  73. var creatingmask;
  74. var SelectedmaskpointId;
  75. var tocreaterect=false;
  76. var tocreatemask=false;
  77. var toCreatePoint = false;
  78. var boxcls = "person";
  79. var mouseonpoint_mask;
  80. var mouseonpoint_rect;
  81. var mouseonrect_rect;
  82. var mouseonmask_mask;
  83. var old_click_x1;
  84. var old_click_y1;
  85. var stretch=false;
  86. var stretch_mask=false;
  87. var isDragging = false;
  88. var showpopVar = false;
  89. var widthstart,widthend;
  90. var heightstart,heightend;
  91. var dragging = false;
  92. var startx = 0;
  93. var starty = 0;
  94. var imgScale = 1;
  95. var fileindex=0;
  96. var lastindex=false;
  97. var isLabelChange = false;
  98. var maxIdNum=0;
  99. function reset_var(){
  100. SelectedRect=null;
  101. SelectedpointId=null;
  102. SelectedmaskpointId = null;
  103. Selectedmask = null;
  104. SelectedPointShape = null;
  105. creatingmask = null;
  106. toCreatePoint = false;
  107. tocreaterect=false;
  108. tocreatemask = false;
  109. boxcls = "person";
  110. mouseonpoint_mask = null;
  111. mouseonpoint_rect=null;
  112. mouseonrect_rect=null;
  113. mouseonmask_mask=null;
  114. old_click_x1=null;
  115. old_click_y1=null;
  116. stretch=false;
  117. stretch_mask = false;
  118. isDragging = false;
  119. showpopVar = false;
  120. widthstart,widthend=null;
  121. heightstart,heightend=null;
  122. imgScale = 1;
  123. dragging = false;
  124. startx = 0;
  125. starty = 0;
  126. }
  127. var label_attributes ;
  128. //by yunpeng zhai
  129. //基本对象的定义 点, 矩形, 多边形MASK
  130. //
  131. function point(x,y){
  132. this.x = x;
  133. this.y = y;
  134. this.isSelected = false;
  135. };
  136. function pointShape(x,y,type,score=1.0){
  137. this.x = x;
  138. this.y = y;
  139. this.isSelected = false;
  140. this.type = type;
  141. this.score = score;
  142. this.id =""; //标识
  143. this.blurred=false;//模糊不清的; 记不清的; 难以区分的; 模棱两可的
  144. this.goodIllumination = false; //照明
  145. this.frontview = false;//正面图
  146. this.other = {};//自定义属性
  147. this.other['region_attributes'] = {};
  148. }
  149. function rectar(x1,y1,x2,y2, type, score=1.0){
  150. // this.x = x;
  151. // this.y = y;
  152. // this.width = width;
  153. // this.height = height;
  154. this.type = type;
  155. this.score = score;
  156. //0--1,
  157. //| |
  158. //2--3
  159. this.points = [new point(x1,y1), new point(x1, y2),new point(x2, y1),new point(x2, y2)];
  160. this.getXYWH = function(){
  161. var x_min=Math.min(this.points[0].x,this.points[1].x,this.points[2].x,this.points[3].x);
  162. var x_max=Math.max(this.points[0].x,this.points[1].x,this.points[2].x,this.points[3].x);
  163. var y_min=Math.min(this.points[0].y,this.points[1].y,this.points[2].y,this.points[3].y);
  164. var y_max=Math.max(this.points[0].y,this.points[1].y,this.points[2].y,this.points[3].y);
  165. return [x_min,y_min,x_max-x_min,y_max-y_min];
  166. }
  167. this.getX1Y1X2Y2 = function(){
  168. var x_min=Math.min(this.points[0].x,this.points[1].x,this.points[2].x,this.points[3].x);
  169. var x_max=Math.max(this.points[0].x,this.points[1].x,this.points[2].x,this.points[3].x);
  170. var y_min=Math.min(this.points[0].y,this.points[1].y,this.points[2].y,this.points[3].y);
  171. var y_max=Math.max(this.points[0].y,this.points[1].y,this.points[2].y,this.points[3].y);
  172. return [x_min,y_min,x_max,y_max];
  173. }
  174. this.getdiapid = function(pid){//获取对角点
  175. var twooverlapped,fouroverlapped;
  176. for (var i=0;i<4;i++){
  177. if ((this.points[pid].x!=this.points[i].x)&&(this.points[pid].y!=this.points[i].y)){
  178. return i;
  179. }
  180. if ((this.points[pid].x!=this.points[i].x)||(this.points[pid].y!=this.points[i].y)){
  181. twooverlapped=i;
  182. }
  183. if (i!=pid) fouroverlapped=i;
  184. }
  185. if (twooverlapped)
  186. return twooverlapped;
  187. return fouroverlapped;
  188. }
  189. this.mouseonpoint = false;
  190. this.mouseonrect = false;
  191. this.isSelected = false;
  192. this.id =""; //标识
  193. this.blurred=false;//模糊不清的; 记不清的; 难以区分的; 模棱两可的
  194. this.goodIllumination = true; //照明
  195. this.frontview = true;//正面图
  196. this.other = {};//自定义属性
  197. this.other['region_attributes'] = {};
  198. //{} -> key = "type" , value = {"type":"dropdown,radio,checkbox", "description" : "..", "options":{"car" : "car", "person" : "person"}, "default_options" : {"car" : "car"}}
  199. // key = "color", value = {"type" : "text", "description" : "..", "def":"11111"}
  200. };
  201. function maskar(x0,y0,type,score=1.0){
  202. this.type = type;
  203. this.points = [new point(x0,y0)];
  204. this.finish = false;
  205. this.mouseonpoint = false;
  206. this.mouseonmask = false;
  207. this.isSelected = false;
  208. this.score = score;
  209. this.getX1Y1 = function(){return [this.points[0].x,this.points[0].y]}
  210. this.getBound = function(){
  211. mlen = this.points.length;
  212. var minX = 999999999, minY = 999999999, maxX = -1, maxY = -1;
  213. for (var i = 0; i < mlen; i ++){
  214. if(minX > this.points[i].x){
  215. minX = this.points[i].x;
  216. }
  217. if(maxX < this.points[i].x){
  218. maxX = this.points[i].x;
  219. }
  220. if(minY > this.points[i].y){
  221. minY = this.points[i].y;
  222. }
  223. if(maxY < this.points[i].y){
  224. maxY = this.points[i].y;
  225. }
  226. }
  227. return [minX, minY, maxX, maxY];
  228. }
  229. this.id =""; //标识
  230. this.blurred=false;//模糊不清的; 记不清的; 难以区分的; 模棱两可的
  231. this.goodIllumination = true; //照明
  232. this.frontview = true;//正面图
  233. this.other = {};//自定义属性
  234. this.other['region_attributes'] = {};
  235. }
  236. function getShowShape(recttype){
  237. var tmp;
  238. if(recttype == "rect"){
  239. tmp = rects;
  240. }else if(recttype == "mask"){
  241. tmp = masks;
  242. }else if(recttype == "pointshape"){
  243. tmp = pointShapes;
  244. }
  245. return tmp;
  246. }
  247. function showPopup(topx,lefty,rectIndex,recttype) {
  248. if (topx > canvas.height){
  249. topx = canvas.height;
  250. }
  251. if (lefty > canvas.width){
  252. lefty = canvas.width;
  253. }
  254. _via_display_area_content_name = VIA_DISPLAY_AREA_CONTENT_NAME.IMAGE;
  255. regions = getShowShape(recttype);
  256. if(isEmpty(regions)){
  257. return;
  258. }
  259. _via_is_region_selected = true;
  260. annotation_editor_show(topx,lefty,rectIndex,recttype);
  261. /*
  262. // 弹框下拉焦点消失
  263. $("select").bind("focus", function(){
  264. if(this.blur){
  265. this.blur();
  266. }
  267. }); */
  268. }
  269. //关闭弹窗函数,设置display为none,传一个参数,把true和false传进去
  270. function hidePopup() {
  271. // document.getElementById("annotation_editor").style.display = "none";
  272. annotation_editor_remove();
  273. for (var i=0;i<rects.length;i++){
  274. rects[i].isSelected = false;
  275. }
  276. // showPopup(bigLocY(x)+145, bigLocX(y) + 235,rectIndex,shapetype);
  277. for (var i=0;i<masks.length;i++){
  278. masks[i].isSelected = false;
  279. }
  280. for (var i=0;i<pointShapes.length;i++){
  281. pointShapes[i].isSelected = false;
  282. }
  283. drawRect();
  284. document.getElementById("boxlabels").innerHTML=boxlabelshtml();
  285. document.getElementById("labelcounttable").innerHTML=boxlabelcounthtml();
  286. }
  287. function copyOneBox(){
  288. copyrects=[];
  289. copymasks=[];
  290. copyPointShapes=[];
  291. for (var i=0;i<rects.length;i++){
  292. if (rects[i].isSelected==true){
  293. copyrects.push(rects[i]);
  294. }
  295. }
  296. // showPopup(bigLocY(x)+145, bigLocX(y) + 235,rectIndex,shapetype);
  297. for (var i=0;i<masks.length;i++){
  298. if (masks[i].isSelected==true){
  299. copymasks.push(masks[i]);
  300. }
  301. }
  302. for (var i=0;i<pointShapes.length;i++){
  303. if (pointShapes[i].isSelected==true){
  304. copyPointShapes.push(pointShapes[i]);
  305. }
  306. }
  307. currentImage=true;
  308. }
  309. function copy(){
  310. // copyrects=[];
  311. // copymasks=[];
  312. // copyPointShapes=[];
  313. copyrects = rects.slice();
  314. copymasks = masks.slice();
  315. copyPointShapes = pointShapes.slice();
  316. console.log("拷贝数据:"+JSON.stringify(copyrects));
  317. currentImage=true;
  318. }
  319. function paste(){
  320. if(currentImage==true){
  321. alert("当前页暂不能粘贴");
  322. return;
  323. }
  324. if(!isEmpty(copyrects)){
  325. var tmpRects = copyrects.slice();
  326. // copyrects.length = 0;
  327. for(var i = 0; i <tmpRects.length; i++){
  328. if (maxIdNum< parseInt(tmpRects[i].other["region_attributes"]["id"])){
  329. maxIdNum = parseInt(tmpRects[i].other["region_attributes"]["id"]);
  330. }
  331. else{
  332. tmpRects[i].other["region_attributes"]["id"] = maxIdNum+1;
  333. tmpRects[i].id = maxIdNum+1;
  334. maxIdNum = maxIdNum +1;
  335. }
  336. tmpRects[i].isSelected=false;
  337. rects.push(tmpRects[i]);
  338. }
  339. console.log("粘贴数据:"+JSON.stringify(rects));
  340. }
  341. if(!isEmpty(copymasks)){
  342. var tmpMasks = copymasks.slice();
  343. // copymasks.length = 0;
  344. for(var i = 0; i <tmpMasks.length; i++){
  345. if (maxIdNum< parseInt(tmpMasks[i].other["region_attributes"]["id"])){
  346. maxIdNum = parseInt(tmpMasks[i].other["region_attributes"]["id"]);
  347. }
  348. else{
  349. tmpMasks[i].other["region_attributes"]["id"] = maxIdNum+1;
  350. tmpMasks[i].id = maxIdNum+1;
  351. maxIdNum = maxIdNum +1;
  352. }
  353. tmpMasks[i].isSelected=false;
  354. masks.push(tmpMasks[i]);
  355. }
  356. }
  357. if(!isEmpty(copyPointShapes)){
  358. var tmpPointShapes = copyPointShapes.slice();
  359. // copyPointShapes.length = 0;
  360. for(var i = 0; i <tmpPointShapes.length; i++){
  361. if (maxIdNum< parseInt(tmpPointShapes[i].other["region_attributes"]["id"])){ //不会出现重复的框
  362. maxIdNum = parseInt(tmpPointShapes[i].other["region_attributes"]["id"]);
  363. }
  364. else{
  365. tmpPointShapes[i].other["region_attributes"]["id"] = maxIdNum+1; //会出现重复的目标框
  366. tmpPointShapes[i].id = maxIdNum+1;
  367. maxIdNum = maxIdNum +1;
  368. }
  369. tmpPointShapes[i]=false;
  370. pointShapes.push(tmpPointShapes[i]);
  371. }
  372. }
  373. drawRect();
  374. updateLabelHtml();
  375. currentImage=true;
  376. }
  377. function undo(){//删除矩形框或者mask
  378. hidePopup();
  379. if(undoShape){
  380. var index = rects.indexOf(undoShape);
  381. if (index!=-1){
  382. rects.splice(index, 1);
  383. }
  384. index = masks.indexOf(undoShape);
  385. if (index!=-1){
  386. masks.splice(index, 1);
  387. }
  388. index = pointShapes.indexOf(undoShape);
  389. if (index!=-1){
  390. pointShapes.splice(index, 1);
  391. }
  392. }
  393. drawRect();
  394. updateLabelHtml();
  395. }
  396. function updateSetting(){
  397. hidePopup();
  398. // show_region_attributes_update_panel();
  399. var set_attributes = document.getElementById("set_attributes")
  400. set_attributes.setAttribute('style', 'overflow:auto;'+'top:' + 185 + 'px;left:'+ 50 +'px;width:'+ 502+'px;position:absolute');
  401. update_attributes_update_panel();
  402. $('#message_panel').css('display','block');
  403. $('#message_panel .content').css('display','inline');
  404. }
  405. function save_attribute(){
  406. var set_attributes = document.getElementById("set_attributes");
  407. var _via_attributes_str = JSON.stringify(_via_attributes['region']);
  408. update_labeltask(_via_attributes_str);
  409. set_attributes.style.display = "none";
  410. document.getElementById('message_panel').style.display = "none";
  411. document.getElementById('message_panel_content').style.display = 'none';
  412. }
  413. function close_attribute(){
  414. set_attributes.style.display = "none";
  415. onload();
  416. document.getElementById("user_input_attribute_id").value='';
  417. document.getElementById('attribute_properties').innerHTML = '';
  418. document.getElementById('attribute_options').innerHTML = '';
  419. document.getElementById("type_color").style.display = "none";
  420. document.getElementById("type_car").style.display = "none";
  421. document.getElementById('message_panel').style.display = "none";
  422. document.getElementById('message_panel_content').style.display = 'none';
  423. }
  424. function close_exist_child_attributes(){
  425. var set_attributes = document.getElementById("atttibute_child");
  426. document.getElementById('atttibute_childe').innerHTML = '';
  427. // var atttibute_child = document.getElementById('atttibute_child');
  428. // if ( atttibute_child ) {
  429. // atttibute_child.style.display = "none";
  430. // // p.remove();
  431. // //
  432. // }
  433. // set_attributes.style.display = "none";
  434. }
  435. function moveAllShape(x,y){
  436. for (var i=0;i<rects.length;i++){
  437. moverect(rects[i],x,y);
  438. }
  439. for (var i=0;i<masks.length;i++){
  440. moveMask(masks[i],x,y);
  441. }
  442. for(var i =0; i < pointShapes.length;i++){
  443. pointShapes[i].x += x;
  444. pointShapes[i].y += y;
  445. }
  446. drawRect();
  447. }
  448. function moveLeftOnePx(){
  449. moveAllShape(-1,0);
  450. }
  451. function moveRightOnePx(){
  452. moveAllShape(1,0);
  453. }
  454. function moveUpOnePx(){
  455. moveAllShape(0,-1);
  456. }
  457. function moveDownOnePx(){
  458. moveAllShape(0,1);
  459. }
  460. function moveSingleShape(x,y) {
  461. if(SelectedRect) {
  462. var index = rects.indexOf(SelectedRect);
  463. moverect(rects[index], x, y);
  464. }
  465. if(Selectedmask){
  466. var index = masks.indexOf(Selectedmask);
  467. moveMask(masks[index], x, y);
  468. }
  469. if(SelectedPointShape) {
  470. var index = pointShapes.indexOf(SelectedPointShape);
  471. pointShapes[index].x += x;
  472. pointShapes[index].y += y;
  473. }
  474. drawRect();
  475. }
  476. function moveLeftSinglePx() {
  477. //$("#hiddenLeft").click();
  478. moveSingleShape(-1,0);
  479. }
  480. function moveRightSinglePx(){
  481. moveSingleShape(1,0);
  482. }
  483. function moveUpSinglePx(){
  484. moveSingleShape(0,-1);
  485. }
  486. function moveDownSinglePx(){
  487. moveSingleShape(0,1);
  488. }
  489. function createRectLabel(){
  490. createrect(getDefaultType());
  491. }
  492. function getDefaultType(){
  493. var tmpType = "";
  494. if(!isEmpty(_via_attributes['region']['type']) && !isEmpty(_via_attributes['region']['type']["default_options"])){
  495. if(_via_attributes['region']['type']['type'] == "dropdown" || _via_attributes['region']['type']['type'] == "radio" || _via_attributes['region']['type']['type'] == "checkbox"){
  496. var tmp = _via_attributes['region']['type']["default_options"];
  497. console.log("aa=" + tmp);
  498. for(var key in tmp){
  499. if(tmp[key] == true){
  500. tmpType = key;
  501. break;
  502. }
  503. }
  504. }
  505. }
  506. console.log("defaulttyype=" + tmpType);
  507. return tmpType;
  508. }
  509. function createMaskLabel(){
  510. createmask(getDefaultType());
  511. }
  512. function createPointLabel(){
  513. createPoint(getDefaultType());
  514. }
  515. function createPoint(classes){
  516. boxcls = classes;
  517. toCreatePoint = true;
  518. }
  519. function createrect(classes){
  520. boxcls = classes;
  521. tocreaterect = true;
  522. }
  523. function createmask(classes){
  524. boxcls = classes;
  525. tocreatemask = true;
  526. }
  527. function cancel(){
  528. hidePopup();
  529. tocreaterect=false;
  530. tocreatemask=false;
  531. if (creatingmask){
  532. creatingmask.finish=true;
  533. creatingmask = null;
  534. }
  535. // boxcls = null;
  536. drawRect();
  537. }
  538. function deleterect(){//删除矩形框或者mask
  539. hidePopup();
  540. if(SelectedRect){
  541. var index = rects.indexOf(SelectedRect);
  542. rects.splice(index, 1);
  543. // regions.splice( index, 1);
  544. SelectedRect=null;
  545. }
  546. if(Selectedmask){
  547. var index = masks.indexOf(Selectedmask);
  548. masks.splice(index, 1);
  549. // regions.splice( index+100, 1);
  550. Selectedmask=null;
  551. }
  552. if(SelectedPointShape){
  553. var index = pointShapes.indexOf(SelectedPointShape);
  554. pointShapes.splice(index, 1);
  555. // regions.splice( index+200, 1);
  556. SelectedPointShape=null;
  557. }
  558. drawRect();
  559. updateLabelHtml();
  560. save();
  561. }
  562. function deleteAllRect(){
  563. hidePopup();
  564. rects.length=0;
  565. masks.length=0;
  566. pointShapes.length=0;
  567. drawRect();
  568. updateLabelHtml();
  569. save();
  570. }
  571. function clearCanvas() {
  572. // 去除所有矩形
  573. rects = [];
  574. masks=[];
  575. pointShapes = [];
  576. // 重新绘制画布.
  577. drawRect();
  578. }
  579. //对象高级操作
  580. //
  581. //标注位置校正 移动,拉伸
  582. function moverect(rect, x, y){
  583. //x y 为拖动坐标增量
  584. for(var i =0; i < rect.points.length;i++){
  585. rect.points[i].x += x;
  586. rect.points[i].y += y;
  587. }
  588. }
  589. function moveMask(mask, x, y){
  590. //x y 为目标位置的左上角
  591. for(var i =0; i < mask.points.length;i++){
  592. mask.points[i].x += x;
  593. mask.points[i].y += y;
  594. }
  595. }
  596. function stretchmask(mask, pid, x, y){
  597. console.log("pid=" + pid + " mask.points.length=" + mask.points.length);
  598. mask.points[pid].x=x;
  599. mask.points[pid].y=y;
  600. }
  601. function stretchrect(rect, pid, x, y){
  602. //x y 为所拖动的点的目标位置
  603. diapid = rect.getdiapid(pid);
  604. rect.points[pid].x=x;
  605. rect.points[pid].y=y;
  606. var first=true;
  607. for (var j=0;j<4;j++){
  608. if((j!=diapid)&&(j!=pid)){
  609. if (first){
  610. rect.points[j].x = x;
  611. rect.points[j].y = rect.points[diapid].y;
  612. first = false;
  613. }
  614. else{
  615. rect.points[j].x = rect.points[diapid].x;
  616. rect.points[j].y = y;
  617. }
  618. }
  619. };
  620. }
  621. //图片操作
  622. //
  623. //
  624. function loadimg(){
  625. reset_var();
  626. var picturePath = labeltastresult[fileindex].pic_image_field;
  627. img.src = ip + "/getgiteaimage?filename=" + picturePath;
  628. var html = picturePath.substring(picturePath.lastIndexOf("/") + 1) + "&nbsp;&nbsp;"+ "(" + (tablePageData.current * pageSize + fileindex + 1) + "/" + tablePageData.total + ")"
  629. document.getElementById("float_text").innerHTML = html;
  630. }
  631. function save(){
  632. hidePopup();
  633. var re = updatelabel(fileindex);
  634. if (re=true){
  635. //window.alert("保存成功!");
  636. }
  637. else{window.alert("保存失败!");}
  638. showfilelist();
  639. }
  640. function clearCache(){
  641. rects = [];
  642. masks = [];
  643. pointShapes = [];
  644. }
  645. function next(){
  646. currentImage = false;
  647. hidePopup();
  648. if(fileindex<labeltastresult.length-1) {
  649. if(loadFinished==true){
  650. updatelabel(fileindex);
  651. }
  652. clearCache();
  653. fileindex=fileindex+1;
  654. loadimg();
  655. showfilelist();
  656. }else{
  657. if((tablePageData.current + 1) * pageSize < tablePageData.total){
  658. if (loadFinished==true){
  659. updatelabel(fileindex);
  660. }
  661. clearCache();
  662. nextPage();
  663. }
  664. }
  665. loadFinished=false;
  666. }
  667. function last(){
  668. currentImage = false;
  669. hidePopup();
  670. if(fileindex>0){
  671. if(loadFinished==true){
  672. loadFinished=false;
  673. updatelabel(fileindex);
  674. }
  675. clearCache();
  676. fileindex=fileindex-1;
  677. loadimg();
  678. showfilelist();
  679. }else{
  680. var current = $('#displayPage1').text();
  681. if(current > 1){
  682. lastindex = true;
  683. if(loadFinished==true){
  684. loadFinished=false;
  685. updatelabel(fileindex);
  686. }
  687. clearCache();
  688. prePage();
  689. lastindex = false;
  690. }
  691. }
  692. }
  693. function clickfilelist(index){
  694. hidePopup();
  695. clearCache();
  696. fileindex = index;
  697. loadimg();
  698. showfilelist();
  699. currentImage = false;
  700. }
  701. //画布操作、
  702. //
  703. //
  704. function onpoint(x,y,pt){
  705. var biasx = Math.abs(x - pt.x);
  706. var biasy = Math.abs(y - pt.y);
  707. if ((biasx<=3) && (biasy<=3)){
  708. return true;
  709. }
  710. else{
  711. return false;
  712. }
  713. }
  714. function onrect(x,y,recta){
  715. rectxywh = recta.getXYWH();
  716. widthstart=rectxywh[0];
  717. widthend=rectxywh[0]+rectxywh[2];
  718. heightstart=rectxywh[1];
  719. heightend=rectxywh[1]+rectxywh[3];
  720. if ((x>=widthstart&&x<(widthend))&&(y>=heightstart)&&(y<(heightend))){
  721. return true;
  722. }
  723. else{
  724. return false;
  725. }
  726. }
  727. function clearboard(){
  728. context.clearRect(0, 0, canvas.width, canvas.height);
  729. }
  730. function fillMask(mask){
  731. context.beginPath();
  732. context.moveTo(bigLocX(mask.points[0].x), bigLocY(mask.points[0].y));
  733. for (var i=1; i<mask.points.length; i++){
  734. context.lineTo(bigLocX(mask.points[i].x), bigLocY(mask.points[i].y));
  735. }
  736. context.closePath();
  737. context.fill();
  738. }
  739. //判断一个点是否在多边形中。
  740. //核心是从这个点出发垂直线或水平线,与多边形相交的次数一定是奇数
  741. function onmask_new(x,y, mask,vs) {
  742. var vs = mask.points;
  743. var inside = false;
  744. for (var i = 0, j = vs.length - 1; i < vs.length; j = i++) {
  745. var xi = vs[i].x, yi = vs[i].y;
  746. var xj = vs[j].x, yj = vs[j].y;
  747. var intersect = ((yi > y) != (yj > y))
  748. && (x < (xj - xi) * (y - yi) / (yj - yi) + xi);
  749. if (intersect) inside = !inside;
  750. }
  751. return inside;
  752. };
  753. function drawRect(x=null,y=null,resize=0) {
  754. //document.getElementById("boxlabels").innerHTML=boxlabelshtml();
  755. //document.getElementById("labelcounttable").innerHTML=boxlabelcounthtml();
  756. //清除画布,准备绘制
  757. context.clearRect(0, 0, canvas.width, canvas.height);
  758. var imgWidth = canvas.width;
  759. var imgHeight = canvas.height
  760. if(imgScale > 1){//当没有放大时,就用画布的大小
  761. imgWidth = canvas.width * imgScale;
  762. imgHeight = canvas.height * imgScale;
  763. }
  764. //console.log("startx=" + startx + " starty=" + starty + " img.width=" + img.width + " imgWidth=" + imgWidth + " imgScale=" + imgScale + " img.width / (canvas.width * imgScale)=" + (img.width / (canvas.width * imgScale)));
  765. context.drawImage(
  766. img, //规定要使用的图像、画布或视频。
  767. startx, starty, //开始剪切的 x 坐标位置。
  768. img.width, img.height, //被剪切图像的高度。
  769. //imgWidth, imgHeight,
  770. 0, 0,//在画布上放置图像的 x 、y坐标位置。
  771. imgWidth, imgHeight //要使用的图像的宽度、高度
  772. //canvas.width,canvas.height
  773. );
  774. //context.drawImage(img, 0, 0, imgWidth, imgHeight, 0, 0, canvas.width, canvas.height);
  775. //context.drawImage(img,0,0,canvas.width,canvas.height);
  776. //遍历画所有矩形框
  777. drawRectShape();
  778. //创建Rect时,显示横竖两条黑线
  779. if (tocreaterect && (x!=-1)){
  780. //row
  781. context.strokeStyle="black"
  782. context.beginPath();
  783. context.moveTo(0,y);
  784. context.lineTo(canvas.width,y);
  785. context.moveTo(x,0);
  786. context.lineTo(x,canvas.height);
  787. context.stroke();
  788. context.closePath();
  789. }
  790. //遍历画所有Mask矩形框
  791. drawMaskShape(x,y);
  792. //遍历画所有的圆点
  793. drawPointShape();
  794. }
  795. function drawPointShape(){
  796. for(var i = 0; i < pointShapes.length; i++){
  797. context.strokeStyle="yellow";
  798. selectColor(pointShapes,i);
  799. context.beginPath();//标志开始一个路径
  800. context.arc(bigLocX(pointShapes[i].x),bigLocY(pointShapes[i].y),5,0,2*Math.PI);//在canvas中绘制圆形
  801. if(pointShapes[i].isSelected){
  802. console.log("choose a point.");
  803. context.fillStyle = "rgba(97, 216, 162, 0.5)";
  804. context.fill();
  805. }
  806. context.stroke()
  807. }
  808. }
  809. function bigLocX(x){
  810. var tmp = img.width / (canvas.width * imgScale);
  811. return x * imgScale - startx/tmp ;
  812. }
  813. function bigLocY(y){
  814. var tmp = img.height / (canvas.height * imgScale);
  815. return y * imgScale - starty /tmp;
  816. }
  817. function smallLocX(x){
  818. var tmp = img.width /canvas.width;
  819. return x / imgScale + startx/tmp;
  820. }
  821. function smallLocY(y){
  822. var tmp = img.height /canvas.height;
  823. return y / imgScale + starty / tmp;
  824. }
  825. //画所有矩形框
  826. function drawRectShape(){
  827. var drawLineWidth = 1;
  828. for(var i=0; i<rects.length; i++) {
  829. var rect = rects[i];
  830. rectxywh = rect.getXYWH();
  831. x1y1x2y2 = rect.getX1Y1X2Y2();
  832. // 绘制矩形
  833. if (rect.isSelected) {
  834. context.fillStyle = "rgba(97, 216, 162, 0.7)";
  835. //context.fillStyle = "rgba(10, 114, 6, 0.5)";
  836. //context.fillRect(bigLocX(rectxywh[0]),bigLocY(rectxywh[1]),bigLocX(rectxywh[2]),bigLocY(rectxywh[3]));
  837. context.fillRect(bigLocX(x1y1x2y2[0]),bigLocY(x1y1x2y2[1]),bigLocX(x1y1x2y2[2]) - bigLocX(x1y1x2y2[0]),bigLocY(x1y1x2y2[3]) - bigLocY(x1y1x2y2[1]));
  838. context.lineWidth = drawLineWidth;
  839. }
  840. else if(rect.mouseonrect || rect.mouseonpoint){//鼠标移到矩形框中或者在矩形点上
  841. context.fillStyle = "rgba(97, 216, 162, 0.2)";
  842. //context.fillStyle = "rgba(10, 114, 6, 0.5)";
  843. //context.fillRect(bigLocX(rectxywh[0]),bigLocY(rectxywh[1]),bigLocX(rectxywh[2]),bigLocY(rectxywh[3]));
  844. context.fillRect(bigLocX(x1y1x2y2[0]),bigLocY(x1y1x2y2[1]),bigLocX(x1y1x2y2[2]) - bigLocX(x1y1x2y2[0]),bigLocY(x1y1x2y2[3]) - bigLocY(x1y1x2y2[1]));
  845. context.lineWidth = drawLineWidth;
  846. }
  847. else{
  848. context.lineWidth = drawLineWidth;
  849. }
  850. // if(rect.type == "person"){
  851. // context.strokeStyle = color_person[ i % 4];
  852. // }else{
  853. context.strokeStyle=color_dict["rect"]; //初始颜色
  854. // }
  855. selectColor(rects,i);
  856. setVerifyLineWidth(rect);
  857. //context.strokeRect(bigLocX(rectxywh[0]),bigLocY(rectxywh[1]),bigLocX(rectxywh[2]),bigLocY(rectxywh[3]),rect.color);
  858. context.strokeRect(bigLocX(x1y1x2y2[0]),bigLocY(x1y1x2y2[1]),bigLocX(x1y1x2y2[2]) - bigLocX(x1y1x2y2[0]),bigLocY(x1y1x2y2[3]) - bigLocY(x1y1x2y2[1]),rect.color);
  859. setVerifyText(rect,bigLocX(x1y1x2y2[0]),bigLocY(x1y1x2y2[1]));
  860. for(var j=0; j<4; j++){
  861. var p = rect.points[j]
  862. // context.fillStyle = "green";
  863. // context.fillRect(p.x-3,p.y-3,6,6);
  864. if (rect.mouseonpoint){
  865. context.fillStyle = color_dict["pointselected"];
  866. context.fillRect(bigLocX(p.x)-5,bigLocY(p.y)-5,10,10);
  867. }
  868. else{
  869. context.fillStyle = color_dict["point"];
  870. context.fillRect(bigLocX(p.x)-3,bigLocY(p.y)-3,6,6);
  871. }
  872. }
  873. }
  874. }
  875. function setVerifyText(rect,x,y){
  876. if(!isEmpty(rect.other.region_attributes.verify)){
  877. if(rect.other.region_attributes.verify != 0){
  878. context.font = "15px Georgia";
  879. context.fillStyle= context.strokeStyle;
  880. context.fillText(verifyMap[rect.other.region_attributes.verify], x,y-5);
  881. }
  882. }
  883. }
  884. function setVerifyLineWidth(rect){
  885. if(!isEmpty(rect.other.region_attributes.verify)){
  886. if(rect.other.region_attributes.verify != 0){
  887. context.lineWidth = 3;
  888. context.strokeStyle = "#DC143C";
  889. }
  890. }
  891. }
  892. function selectColor(regions,i){
  893. if(!isEmpty(_via_attributes['region']['type'])){
  894. var dict = _via_attributes['region']['type']["options"];
  895. var color_num=0;
  896. for (var key in dict){
  897. if (key==regions[i].other.region_attributes.type){
  898. context.strokeStyle=color_all[String(color_num)];
  899. break;
  900. }
  901. color_num++;
  902. }
  903. }
  904. }
  905. function drawMaskShape(x,y){
  906. for (var i=0; i<masks.length; i++){
  907. context.strokeStyle="purple"
  908. var mask =masks[i];
  909. if (mask.isSelected){
  910. context.lineWidth = 3;
  911. }
  912. else{
  913. context.lineWidth = 2;
  914. }
  915. selectColor(masks,i);
  916. for (var j=1; j<mask.points.length; j++){
  917. context.beginPath();
  918. context.moveTo(bigLocX(mask.points[j-1].x), bigLocY(mask.points[j-1].y));
  919. context.lineTo(bigLocX(mask.points[j].x),bigLocY(mask.points[j].y));
  920. context.stroke();
  921. // context.closePath();
  922. }
  923. if(mask.finish){
  924. context.moveTo(bigLocX(mask.points[mask.points.length-1].x), bigLocY(mask.points[mask.points.length-1].y));
  925. context.lineTo(bigLocX(mask.points[0].x), bigLocY(mask.points[0].y));
  926. context.stroke();
  927. context.closePath();
  928. // 绘制Mask
  929. if (mask.isSelected) {
  930. context.fillStyle = "rgba(97, 216, 162, 0.5)";
  931. fillMask(mask);
  932. }
  933. else if(mask.mouseonmask || mask.mouseonpoint){
  934. context.fillStyle = "rgba(97, 216, 162, 0.2)";
  935. fillMask(mask);
  936. }
  937. }
  938. else{
  939. if(x&&y){
  940. context.beginPath();
  941. context.moveTo(bigLocX(mask.points[mask.points.length-1].x),bigLocY(mask.points[mask.points.length-1].y));
  942. context.lineTo(x,y);
  943. context.stroke();
  944. // context.closePath();
  945. }
  946. }
  947. for (var j=0; j<mask.points.length; j++){
  948. var p = mask.points[j]
  949. if (onpoint(smallLocX(x),smallLocY(y),p)){
  950. context.fillStyle = color_dict["pointselected"];
  951. context.fillRect(bigLocX(p.x)-5,bigLocY(p.y)-5,10,10);
  952. }
  953. else{
  954. context.fillStyle = color_dict["point"];
  955. context.fillRect(bigLocX(p.x)-3,bigLocY(p.y)-3,6,6);
  956. }
  957. }
  958. }
  959. }
  960. function resetSelectShapeEmpty(){
  961. if (Selectedmask != null){
  962. console.log("set select mask is null.");
  963. if (SelectedmaskpointId != null){
  964. Selectedmask.points[SelectedmaskpointId].isSelected = false;
  965. SelectedmaskpointId = null;
  966. }
  967. Selectedmask.isSelected = false;
  968. Selectedmask = null;
  969. }
  970. if (SelectedRect != null){
  971. console.log("set select rect is null.");
  972. if (SelectedpointId != null){
  973. SelectedRect.points[SelectedpointId].isSelected = false;
  974. SelectedpointId= null;
  975. }
  976. SelectedRect.isSelected = false;
  977. SelectedRect = null;
  978. }
  979. if(SelectedPointShape != null){
  980. SelectedPointShape = null;
  981. }
  982. }
  983. function clickPointInMask(clickX,clickY){
  984. //查看点击的点是否是Mask的标注点,如果是,则着重显示该点。
  985. for(var i=masks.length-1; i>=0; i--) {
  986. var mask = masks[i];
  987. var maskpoints = mask.points
  988. for (var j=0;j<maskpoints.length;j++){
  989. var pt = maskpoints[j];
  990. if (onpoint(smallLocX(clickX),smallLocY(clickY),pt)){
  991. mask.isSelected=true;
  992. Selectedmask = mask;
  993. stretch_mask = true;
  994. SelectedmaskpointId=j;
  995. //更新显示
  996. drawRect(clickX,clickY);
  997. //停止搜索
  998. return true;
  999. }
  1000. }
  1001. }
  1002. //检查点击的点是否在某个Mask的范围内,如果是,则该Mask的范围内背景色需要修改,显示该Mask的标注信息
  1003. for(var i=masks.length-1; i>=0; i--) {
  1004. var mask = masks[i];
  1005. if (onmask_new(smallLocX(clickX),smallLocY(clickY),mask)){
  1006. Selectedmask = mask;
  1007. console.log("at mask.clickX=" + clickX + " clicky=" + clickY);
  1008. mask.isSelected=true;
  1009. Selectedmask = mask;
  1010. // 允许被拉伸
  1011. stretch_mask =true;
  1012. //允许拖动
  1013. isDragging = true;
  1014. old_click_x1=clickX;
  1015. old_click_y1=clickY;
  1016. //更新显示
  1017. drawRect();
  1018. //弹出标注信息框
  1019. var bound = mask.getBound();
  1020. var new_region_id =i;
  1021. regions = masks;
  1022. select_only_region(new_region_id);
  1023. showPopup(bigLocY(bound[3])+5, bigLocX(bound[2])+5,i,"mask");
  1024. // showPopup(bigLocY(bound[3])+145, bigLocX(bound[2]) + 235,i,"mask");
  1025. document.getElementById("boxlabels").innerHTML=boxlabelshtml();
  1026. document.getElementById("labelcounttable").innerHTML=boxlabelcounthtml();
  1027. //停止搜索
  1028. return true;
  1029. }else{
  1030. //console.log("not at mask.clickX=" + clickX + " clicky=" + clickY);
  1031. }
  1032. }
  1033. return false;
  1034. }
  1035. function clickPointInRect(clickX,clickY){
  1036. // //查看点击的点是否是Rect的标注点,如果是,则着重显示该点。
  1037. for(var i=rects.length-1; i>=0; i--) {
  1038. var rect = rects[i];
  1039. var rectpoints = rect.points
  1040. for (var j=0;j<rectpoints.length;j++){
  1041. var pt = rectpoints[j];
  1042. //console.log("clickX,clickY=" + clickX + "," + clickY + " smallLocX,smallLocY=" + smallLocX(clickX) + "," +smallLocY(clickY) + " pt.x,pt.y=" + pt.x + "," + pt.y);
  1043. if (onpoint(smallLocX(clickX),smallLocY(clickY),pt)){
  1044. pt.isSelected=true;
  1045. rect.isSelected=true;
  1046. SelectedRect = rect;
  1047. SelectedpointId = j;
  1048. stretch = true;//允许拉伸
  1049. console.log("choose rect 3333:");
  1050. //更新显示
  1051. drawRect();
  1052. //停止搜索
  1053. return true;
  1054. }
  1055. }
  1056. }
  1057. for(var i=rects.length-1; i>=0; i--) {
  1058. var rect = rects[i];
  1059. if (onrect(smallLocX(clickX),smallLocY(clickY),rect)){
  1060. SelectedRect = rect;
  1061. old_click_x1=clickX;
  1062. old_click_y1=clickY;
  1063. //选择新圆圈
  1064. rect.isSelected = true;
  1065. //允许拖拽
  1066. isDragging = true;
  1067. //更新显示
  1068. drawRect();
  1069. xy = rect.getX1Y1X2Y2();
  1070. console.log("choose rect 2: top=" + clickX + " left=" + clickY + " x1=" + xy[0] + " y1=" + xy[1] + " x2=" + xy[2] + " y2=" + xy[3] + " startx=" + startx + " starty=" + starty);
  1071. select_only_region(i);
  1072. showPopup(bigLocY(xy[1])+5, bigLocX(xy[2])+5 , i,"rect");
  1073. // showPopup(bigLocY(xy[3])+145, bigLocX(xy[2]) + 235,i,"rect");
  1074. document.getElementById("boxlabels").innerHTML=boxlabelshtml();
  1075. document.getElementById("labelcounttable").innerHTML=boxlabelcounthtml();
  1076. //停止搜索
  1077. return true;
  1078. }
  1079. }
  1080. return false;
  1081. }
  1082. function clickPointInPointShape(clickX,clickY){
  1083. var t = -1;
  1084. for(var i = 0; i < pointShapes.length; i++){
  1085. if (onpoint(smallLocX(clickX),smallLocY(clickY),pointShapes[i])){
  1086. console.log("clickX=," + clickX + "clickY=," + clickY + " pointShapes[i].x=" + + pointShapes[i].x + "pointShapes[i].y=" + pointShapes[i].y);
  1087. pointShapes[i].isSelected=true;
  1088. SelectedPointShape = pointShapes[i];
  1089. t = i;
  1090. }else{
  1091. pointShapes[i].isSelected=false;
  1092. }
  1093. }
  1094. if( t >= 0){
  1095. drawRect();
  1096. select_only_region(t);
  1097. showPopup(bigLocY(SelectedPointShape.y) +5, bigLocX(SelectedPointShape.x) +5,t,"pointshape");
  1098. // showPopup(bigLocY(SelectedPointShape.y) + 165, bigLocX(SelectedPointShape.x) + 250,t,"pointshape");
  1099. //showPopup(bigLocY(SelectedPointShape.y) + 165, bigLocX(SelectedPointShape.x) + 250,t,"pointshape");
  1100. document.getElementById("boxlabels").innerHTML=boxlabelshtml();
  1101. document.getElementById("labelcounttable").innerHTML=boxlabelcounthtml();
  1102. return true;
  1103. }
  1104. return false;
  1105. }
  1106. //交互
  1107. //画布内鼠标响应操作
  1108. function canvasClick(e) {
  1109. // 取得画布上被单击的点
  1110. var clickX = e.pageX - getElementLeft(canvas);
  1111. var clickY = e.pageY - getElementTop(canvas);
  1112. var smallClickX = smallLocX(clickX);
  1113. var smallClickY = smallLocY(clickY);
  1114. if (tocreaterect){
  1115. var rect=new rectar(smallClickX,smallClickY,smallClickX,smallClickY,boxcls);
  1116. rects.push(rect);
  1117. console.log("draw rect...10");
  1118. showpopVar = true;
  1119. tocreaterect=false;
  1120. hidePopup();
  1121. undoShape = rect;
  1122. }
  1123. if (tocreatemask){
  1124. showpopVar = true;
  1125. hidePopup();
  1126. if (creatingmask == null){
  1127. var mask=new maskar(smallClickX,smallClickY,boxcls);
  1128. masks.push(mask);
  1129. Selectedmask = mask;
  1130. creatingmask = mask;
  1131. }
  1132. else{
  1133. if (onpoint(smallClickX,smallClickY,creatingmask.points[0])){
  1134. Selectedmask.finish=true;
  1135. creatingmask=null;
  1136. tocreatemask=false;
  1137. drawRect();
  1138. var new_region_id =masks.length-1;
  1139. var bound = masks[new_region_id].getBound();
  1140. regions = masks;
  1141. set_region_annotations_to_default_value( new_region_id );
  1142. select_only_region(new_region_id);
  1143. showPopup(bigLocY(bound[3])+5, bigLocX(bound[2])+5,new_region_id,"mask");
  1144. // showPopup(bigLocY(bound[3])+145, bigLocX(bound[2]) + 235,i,"mask");
  1145. document.getElementById("boxlabels").innerHTML=boxlabelshtml();
  1146. document.getElementById("labelcounttable").innerHTML=boxlabelcounthtml();
  1147. undoShape = masks[new_region_id];
  1148. resetSelectShapeEmpty();
  1149. return;
  1150. }
  1151. creatingmask.points.push(new point(smallClickX,smallClickY))
  1152. }
  1153. }
  1154. if(toCreatePoint){
  1155. console.log("point x,y=" + clickX + "," + clickY);
  1156. var pointObj = new pointShape(smallClickX,smallClickY,boxcls);
  1157. pointShapes.push(pointObj);
  1158. var len_points = pointShapes.length;
  1159. var new_region_id =len_points-1;
  1160. regions = pointShapes;
  1161. set_region_annotations_to_default_value(new_region_id);
  1162. toCreatePoint = false;
  1163. undoShape = pointShapes[new_region_id];
  1164. }
  1165. //将选择信息设置为空,在下面重新查找设置
  1166. resetSelectShapeEmpty();
  1167. if(clickPointInPointShape(clickX,clickY)){
  1168. return;
  1169. }
  1170. //如果点在Mask内,已经画完了,则返回。
  1171. if(clickPointInMask(clickX,clickY)){
  1172. return;
  1173. }
  1174. //如果点在Rect内,已经画完了,则返回。
  1175. if(clickPointInRect(clickX,clickY)){
  1176. return;
  1177. }
  1178. //如果点不在标注区域内
  1179. drawRect(clickX,clickY);
  1180. hidePopup();
  1181. dragging = true;
  1182. old_click_x1 = clickX;
  1183. old_click_y1 = clickY;
  1184. }
  1185. function dragRect(e) {
  1186. // 取得鼠标位置
  1187. var x = e.pageX - getElementLeft(canvas);
  1188. var y = e.pageY - getElementTop(canvas);
  1189. var smallX = smallLocX(x);
  1190. var smallY = smallLocY(y);
  1191. if (tocreaterect || tocreatemask){
  1192. drawRect(x,y);
  1193. }
  1194. //悬停变色
  1195. var found=false;
  1196. for(var i=rects.length-1; i>=0; i--) {
  1197. var rect = rects[i];
  1198. var rectpoints = rect.points
  1199. for (var j=0;j<rectpoints.length;j++){
  1200. var pt = rectpoints[j];
  1201. if (onpoint(smallX,smallY,pt)){
  1202. rect.mouseonpoint=true;
  1203. mouseonpoint_rect = rect;
  1204. //更新显示
  1205. drawRect(x,y);
  1206. //停止搜索
  1207. found=true;
  1208. break;
  1209. }
  1210. }
  1211. if (found){
  1212. break;
  1213. }
  1214. }
  1215. for(var i=masks.length-1; i>=0; i--) {
  1216. var mask = masks[i];
  1217. var maskpoints = mask.points
  1218. for (var j=0;j<maskpoints.length;j++){
  1219. var pt = maskpoints[j];
  1220. if (onpoint(smallX,smallY,pt)){
  1221. mask.mouseonpoint=true;
  1222. mouseonpoint_mask = mask;
  1223. //更新显示
  1224. drawRect(x,y);
  1225. //停止搜索
  1226. found=true;
  1227. break;
  1228. }
  1229. }
  1230. if (found){
  1231. break;
  1232. }
  1233. }
  1234. if ((!found)&& (mouseonpoint_mask!=null)&&(!stretch)) {
  1235. mouseonpoint_mask.mouseonpoint=false;
  1236. mouseonpoint_mask=null;
  1237. drawRect(x,y);
  1238. }
  1239. if ((!found)&& (mouseonpoint_rect!=null)&&(!stretch)) {
  1240. mouseonpoint_rect.mouseonpoint=false;
  1241. mouseonpoint_rect=null;
  1242. drawRect(x,y);
  1243. }
  1244. if (!found){//不在点上
  1245. for(var i=rects.length-1; i>=0; i--) {
  1246. var rect = rects[i];
  1247. if (onrect(smallX,smallY,rect)){
  1248. if (mouseonrect_rect) {mouseonrect_rect.mouseonrect=false;}
  1249. rect.mouseonrect=true;
  1250. mouseonrect_rect = rect;
  1251. //更新显示
  1252. drawRect(x,y);
  1253. //停止搜索
  1254. found=true;
  1255. break;
  1256. }
  1257. }
  1258. for(var i=masks.length-1; i>=0; i--) {
  1259. var mask = masks[i];
  1260. var maskpoints = mask.points
  1261. if (onmask_new(smallX,smallY,mask)){
  1262. if (mouseonmask_mask) {mouseonmask_mask.mouseonmask=false;}
  1263. mask.mouseonmask=true;
  1264. mouseonmask_mask = mask;
  1265. //更新显示
  1266. drawRect(x,y);
  1267. //停止搜索
  1268. found=true;
  1269. break;
  1270. }
  1271. }
  1272. if((!found)&& (mouseonrect_rect!=null)){
  1273. mouseonrect_rect.mouseonrect=false;
  1274. mouseonrect_rect=null;
  1275. drawRect(x,y);
  1276. }
  1277. if((!found)&& (mouseonmask_mask!=null)){
  1278. mouseonmask_mask.mouseonmask=false;
  1279. mouseonmask_mask=null;
  1280. drawRect(x,y);
  1281. }
  1282. }
  1283. // 判断矩形是否开始拖拽
  1284. if (isDragging == true) {
  1285. // 判断拖拽对象是否存在
  1286. if (SelectedRect != null) {
  1287. // 将圆圈移动到鼠标位置
  1288. //console.log("old(" + old_click_x1 + "," + old_click_y1 +") new(" + x + "," + y + ")");
  1289. moverect(SelectedRect, x-old_click_x1, y-old_click_y1);
  1290. old_click_x1 = x;
  1291. old_click_y1 = y;
  1292. // 更新画布
  1293. drawRect();
  1294. }else if(Selectedmask != null){
  1295. moveMask(Selectedmask, x-old_click_x1, y-old_click_y1);
  1296. old_click_x1 = x;
  1297. old_click_y1 = y;
  1298. // 更新画布
  1299. drawRect();
  1300. }
  1301. hidePopup();
  1302. }
  1303. //判断是否开始拉伸
  1304. if (stretch) {
  1305. stretchrect(SelectedRect, SelectedpointId, smallLocX(x), smallLocY(y));
  1306. drawRect();
  1307. document.getElementById("boxlabels").innerHTML=boxlabelshtml();
  1308. document.getElementById("labelcounttable").innerHTML=boxlabelcounthtml();
  1309. }
  1310. //判断mask是否开始拉伸
  1311. if (stretch_mask && SelectedmaskpointId != null) {
  1312. stretchmask(Selectedmask, SelectedmaskpointId, smallLocX(x), smallLocY(y));
  1313. drawRect();
  1314. }
  1315. if(dragging){
  1316. var dx = x - old_click_x1;
  1317. var dy = y - old_click_y1;
  1318. startx -= dx;
  1319. starty -= dy;
  1320. console.log("x=" + x + " y=" + y + " move x=" + dx + " move y=" + dy + " startx=" +startx + ",starty=" + starty);
  1321. drawRect();
  1322. old_click_x1 = x;
  1323. old_click_y1 = y;
  1324. }
  1325. };
  1326. function stopDragging() {
  1327. isDragging = false;
  1328. dragging = false;
  1329. stretch=false;
  1330. stretch_mask=false;
  1331. //console.log("choose rect 10:")
  1332. if (tocreaterect) {
  1333. drawRect(-1,-1);
  1334. }
  1335. if(showpopVar){
  1336. showpopVar= false;
  1337. document.getElementById("boxlabels").innerHTML=boxlabelshtml();
  1338. document.getElementById("labelcounttable").innerHTML=boxlabelcounthtml();
  1339. for(var i=rects.length-1; i>=0; i--) {
  1340. var rect = rects[i];
  1341. if (rect.isSelected){
  1342. xy = rect.getX1Y1X2Y2();
  1343. console.log("create rect show: x1=" + xy[0] + " y1=" + xy[1] + " x2=" + xy[2] + " y2=" + xy[3] + " startx=" + startx + ",starty=" + starty);
  1344. // wang
  1345. // var original_img_region = new file_region();
  1346. var new_region_id =i;
  1347. regions = rects;
  1348. set_region_annotations_to_default_value( new_region_id );
  1349. select_only_region(new_region_id);
  1350. showPopup(bigLocY(xy[3])+5, bigLocX(xy[2])+5 , i,"rect");
  1351. // showPopup(bigLocY(xy[3])+145, bigLocX(xy[2]) + 235, i,"rect");
  1352. //停止搜索
  1353. return;
  1354. }
  1355. }
  1356. for(var i=masks.length-1; i>=0; i--) {
  1357. var mask = masks[i];
  1358. if (mask.isSelected && mask.finish){
  1359. var new_region_id =i;
  1360. regions = masks;
  1361. select_only_region(new_region_id);
  1362. set_region_annotations_to_default_value(new_region_id);
  1363. var bound = mask.getBound();
  1364. showPopup(bigLocY(bound[3])+5, bigLocX(bound[2])+5 ,i,"mask");
  1365. // showPopup(bigLocY(bound[3])+145, bigLocX(bound[2]) + 235,i,"mask");
  1366. console.log("create mask--show...13");
  1367. //停止搜索
  1368. return;
  1369. }
  1370. }
  1371. for(var i=pointShapes.length-1; i>=0; i--) {
  1372. var pointShape = pointShapes[i];
  1373. if (pointShape.isSelected && pointShape.finish){
  1374. var new_region_id =i;
  1375. regions = pointShapes;
  1376. select_only_region(new_region_id);
  1377. set_region_annotations_to_default_value(new_region_id);
  1378. // var bound = mask.getBound();
  1379. showPopup(bigLocY(pointShape.x)+5, bigLocX(pointShape.y)+5 ,i,"pointShapes");
  1380. // showPopup(bigLocY(pointShape.x)+145, bigLocX(pointShape.y) + 235,i,"pointShapes");
  1381. console.log("create mask--show...13");
  1382. //停止搜索
  1383. return;
  1384. }
  1385. }
  1386. }
  1387. };
  1388. function updateLabelHtml(){
  1389. document.getElementById("boxlabels").innerHTML=boxlabelshtml();
  1390. document.getElementById("labelcounttable").innerHTML=boxlabelcounthtml();
  1391. }
  1392. //边栏
  1393. //任务信息
  1394. function showtaskinfo(){
  1395. $('#task_info').text(label_task_info.task_name);
  1396. $('#task_progress').text(label_task_info.task_status_desc);
  1397. var percent=label_task_info.task_status_desc.split('(')[0]
  1398. $("div[role='progressbar']").width(percent)
  1399. $("div[role='progressbar']").attr('aria-valuemax',tablePageData.total)
  1400. }
  1401. var orderType = 1;
  1402. var findLast = 0;
  1403. function showOrder(value){
  1404. console.log("--------",value)
  1405. hidePopup();
  1406. if (value == "1"){ //文件名排序
  1407. console.log("value=1")
  1408. orderType = 1;
  1409. findLast = 0;
  1410. }
  1411. else if (value == "2"){
  1412. console.log("value=2")
  1413. orderType = 0;
  1414. findLast = 0;
  1415. }
  1416. else if (value == "3"){
  1417. orderType = 0;
  1418. findLast = 3;
  1419. }
  1420. page(0,pageSize);
  1421. }
  1422. function skipLast(){
  1423. hidePopup();
  1424. if (orderType == 0){
  1425. return ;
  1426. }
  1427. findLast = 1;
  1428. page(0,pageSize);
  1429. }
  1430. function isVerified(){
  1431. if(userType == 2 && label_task_status == 1){
  1432. return true;
  1433. }
  1434. return false;
  1435. }
  1436. //显示文件列表
  1437. function showfilelist(){
  1438. var htmlstr="";
  1439. for (var i=0;i<labeltastresult.length;i++){
  1440. var fname = labeltastresult[i].pic_image_field.substring(labeltastresult[i].pic_image_field.lastIndexOf('/') + 1);
  1441. var isfinished = labeltastresult[i].label_status;
  1442. if(isVerified()){
  1443. isfinished = labeltastresult[i].verify_status - 1;
  1444. }
  1445. var lablebg=" style=\"cursor:pointer\"";
  1446. var classStr = "style=\"color:#FF6200;background: transparent;border: 0;\"";
  1447. var finish="未完成";
  1448. if (isfinished=="0"){finish="已完成";classStr = "style=\"color:#27c24c;background: transparent;border: 0;\"";}
  1449. if (i==fileindex){lablebg=" style=\"color:#fff;cursor:pointer;\"";classStr = "style=\"color:#04B3E5;background: transparent;border: 0;\"";finish="标注中"}
  1450. if(isVerified()){
  1451. htmlstr = htmlstr+"<tr onclick=\"clickfilelist("+i+");\""+ lablebg+"> <td width=\"70\"" +"style=\"vertical-align:middle\""+ classStr + ">"+"<button"+classStr+" type=\"button\" onclick=\"changeVerifyStatus("+i+");\" style=\"border:none;background:none\">"+finish +"</button>"+"</td><td>"+ fname+ "</td></tr>";
  1452. }else{
  1453. htmlstr = htmlstr+"<tr onclick=\"clickfilelist("+i+");\""+lablebg+"><td>"+fname+"</td><td width=\"110\""+"style=\"vertical-align:middle\">"+"<button onclick=\"changeStatus("+i+");\" "+ classStr +" style=\"border:none;background:none\">"+finish +"</button>"+"</td></tr>";
  1454. }
  1455. };
  1456. document.getElementById("filelist").innerHTML=htmlstr;
  1457. }
  1458. function changeStatus(i){
  1459. var tmpId='changeStatus_'+i;
  1460. var htmlstr= "<div class=\"panel\" style=\"background:#020004;border:0.5px solid #222324;margin-bottom:0;border-radius:0;\""
  1461. +">"
  1462. +"<label for=\"st\" style=\"padding:0.8em;color: #7092BE;\"> 标注状态修改为:</label>"+
  1463. "<select id="+tmpId+" name=\"标注状态\" style=\"text-align:center;border-radius:4px;margin-left: 1em;\">"+
  1464. "<option value=0 selected=\"\">已完成</option>"+
  1465. "<option value=1 >未完成</option>"+
  1466. "</select>"+
  1467. "<button onclick=\"updateStatus("+i+");\" class=\"btn\" style=\"padding:0;margin-left:3em;background: transparent;border:0;color:#04B3E5;\">提交</button>"
  1468. +"</div>"
  1469. document.getElementById("labelStatus").innerHTML=htmlstr;
  1470. }
  1471. // function changeStatus(i){
  1472. // var tmpId='changeStatus_'+i;
  1473. // var htmlstr= "<div class=\"panel\" style=background:#ffff;border: 1px solid rgba(0,0,0,0.2);border-radius: 6px;top:10px;"
  1474. // +">"
  1475. // +"<label for=\"st\" style=\"margin:15px;color:#333\"> 标注状态修改为:</label>"+
  1476. // "<select id="+tmpId+" name=\"标注状态\" style=\"width:100px;text-align:center;border-radius:4px;\">"+
  1477. // "<option value=0 selected=\"\">已完成</option>"+
  1478. // "<option value=1 >未完成</option>"+
  1479. // "</select>"+
  1480. // "<br />"+
  1481. // "<button onclick=\"updateStatus("+i+");\" class=\"btn btn-default\" style=\"margin:0 auto;display: block;border-radius:5px;width: 50px;\">提交</button>"
  1482. // +"</div>"
  1483. // document.getElementById("labelStatus").innerHTML=htmlstr;
  1484. // }
  1485. function changeVerifyStatus(i){
  1486. var tmpId='changeStatus_'+i;
  1487. var htmlstr= "<div class=\"panel\" style=background:#ffff;border: 1px solid rgba(0,0,0,0.2);border-radius: 6px;top:10px;"
  1488. +">"
  1489. +"<label for=\"st\" style=\"margin:15px;color:#333\"> 审核状态修改为:</label>"+
  1490. "<select id="+tmpId+" name=\"审核状态\" style=\"width:100px;text-align:center;border-radius:4px;\">"+
  1491. "<option value=1 selected=\"\">已完成</option>"+
  1492. "<option value=0 >未完成</option>"+
  1493. "</select>"+
  1494. "<br />"+
  1495. "<button onclick=\"updateVerifyStatus("+i+");\" class=\"btn btn-default\" style=\"margin:0 auto;display: block;border-radius:5px;width: 50px;\">提交</button>"
  1496. +"</div>"
  1497. document.getElementById("labelStatus").innerHTML=htmlstr;
  1498. }
  1499. function updateStatus(i){
  1500. var status_id = 'changeStatus_'+i;
  1501. var label_status=document.getElementById(status_id).value;
  1502. labeltastresult[fileindex].label_status = label_status;
  1503. $.ajax({
  1504. type:"PATCH",
  1505. url:ip + "/gitea/label-task-item-status/",
  1506. contentType:'application/json',
  1507. headers: {
  1508. authorization:token,
  1509. },
  1510. dataType:"json",
  1511. async:false,
  1512. data:JSON.stringify({'id':labeltastresult[fileindex].id,
  1513. 'label_task_id':label_task_info.id,
  1514. 'label_status':label_status,
  1515. }),
  1516. success:function(json){
  1517. showfilelist();
  1518. document.getElementById("labelStatus").innerHTML = "";
  1519. return true;
  1520. },
  1521. error:function(response) {
  1522. redirect(response);
  1523. }
  1524. });
  1525. }
  1526. function updateVerifyStatus(i){
  1527. var status_id = 'changeStatus_'+i;
  1528. var verify_status=document.getElementById(status_id).value;
  1529. labeltastresult[fileindex].verify_status = verify_status;
  1530. $.ajax({
  1531. type:"PATCH",
  1532. url:ip + "/gitea/label-task-item-verify-status/",
  1533. contentType:'application/json',
  1534. headers: {
  1535. authorization:token,
  1536. },
  1537. dataType:"json",
  1538. async:false,
  1539. data:JSON.stringify({'id':labeltastresult[fileindex].id,
  1540. 'label_task_id':label_task_info.id,
  1541. 'verify_status':verify_status,
  1542. }),
  1543. success:function(json){
  1544. showfilelist();
  1545. document.getElementById("labelStatus").innerHTML = "";
  1546. return true;
  1547. },
  1548. error:function(response) {
  1549. redirect(response);
  1550. }
  1551. });
  1552. }
  1553. //this.id =""; //标识
  1554. //this.blurred=false;//模糊不清的; 记不清的; 难以区分的; 模棱两可的
  1555. //this.goodIllumination = true; //照明
  1556. //this.frontview = true;//正面图
  1557. function parse_labelinfo(labelinfo){
  1558. rects.length = 0;
  1559. masks.length = 0;
  1560. pointShapes.length = 0;
  1561. if(!isEmpty(labelinfo)){
  1562. // console.log("标注信息:"+labelinfo);
  1563. var label_arr = JSON.parse(labelinfo);
  1564. for(var i=0;i<label_arr.length;i++){
  1565. if(!isEmpty(label_arr[i].mask)){
  1566. cls=label_arr[i].class_name;
  1567. var tmpMask = new maskar(getCanvasLocationX(label_arr[i].mask[0]),getCanvasLocationY(label_arr[i].mask[1]),cls);
  1568. for(var j = 2; j < label_arr[i].mask.length; j+=2){
  1569. tmpMask.points.push(new point(getCanvasLocationX(label_arr[i].mask[j]),getCanvasLocationY(label_arr[i].mask[j+1])));
  1570. }
  1571. if(!isEmpty(label_arr[i].id)){
  1572. tmpMask.id= label_arr[i].id;
  1573. }
  1574. if(!isEmpty(label_arr[i].blurred)){
  1575. tmpMask.blurred = label_arr[i].blurred;
  1576. }
  1577. if(!isEmpty(label_arr[i].goodIllumination)){
  1578. tmpMask.goodIllumination = label_arr[i].goodIllumination;
  1579. }
  1580. if(!isEmpty(label_arr[i].frontview)){
  1581. tmpMask.frontview = label_arr[i].frontview;
  1582. }
  1583. if(!isEmpty(label_arr[i].other)){
  1584. tmpMask.other = label_arr[i].other;
  1585. }else if (isEmpty(label_arr[i].other)){
  1586. tmpMask.other["region_attributes"]["type"] = tmpMask.type;
  1587. tmpMask.other["region_attributes"]["id"] = tmpMask.id;
  1588. }
  1589. tmpMask.finish = true;
  1590. if (maxIdNum< parseInt(tmpMask.other["region_attributes"]["id"])){
  1591. maxIdNum = parseInt(tmpMask.other["region_attributes"]["id"]);
  1592. }
  1593. masks.push(tmpMask);
  1594. }
  1595. else if(!isEmpty(label_arr[i].box)){
  1596. x1 = getCanvasLocationX(label_arr[i].box[0]);
  1597. y1 = getCanvasLocationY(label_arr[i].box[1]);
  1598. x2 = getCanvasLocationX(label_arr[i].box[2]);
  1599. y2 = getCanvasLocationY(label_arr[i].box[3]);
  1600. cls=label_arr[i].class_name;
  1601. score = label_arr[i].score;
  1602. var rect = new rectar(x1,y1,x2,y2,cls,score);
  1603. if(!isEmpty(label_arr[i].id)){
  1604. rect.id= label_arr[i].id;
  1605. }
  1606. if(!isEmpty(label_arr[i].blurred)){
  1607. rect.blurred = label_arr[i].blurred;
  1608. }
  1609. if(!isEmpty(label_arr[i].goodIllumination)){
  1610. rect.goodIllumination = label_arr[i].goodIllumination;
  1611. }
  1612. if(!isEmpty(label_arr[i].frontview)){
  1613. rect.frontview = label_arr[i].frontview;
  1614. }
  1615. if(!isEmpty(label_arr[i].other)){
  1616. rect.other = label_arr[i].other;
  1617. }
  1618. // else if (isEmpty(label_arr[i].other) && (isEmpty(label_attributes) || Object.keys(label_attributes).length == 0)){
  1619. else if (isEmpty(label_arr[i].other)){
  1620. rect.other["region_attributes"]["type"] = rect.type;
  1621. rect.other["region_attributes"]["id"] = rect.id;
  1622. }
  1623. if (maxIdNum< parseInt(rect.other["region_attributes"]["id"])){
  1624. maxIdNum = parseInt(rect.other["region_attributes"]["id"]);
  1625. }
  1626. rects.push(rect);
  1627. }
  1628. else if(!isEmpty(label_arr[i].keypoints)){
  1629. cls=label_arr[i].class_name;
  1630. score = label_arr[i].score;
  1631. var pointShapeObj = new pointShape(getCanvasLocationX(label_arr[i].keypoints[0]),getCanvasLocationY(label_arr[i].keypoints[1]),cls,score);
  1632. if(!isEmpty(label_arr[i].other)){
  1633. pointShapeObj.other = label_arr[i].other;
  1634. }
  1635. else if (isEmpty(label_arr[i].other)){
  1636. pointShapeObj.other["region_attributes"]["type"] = pointShapeObj.type;
  1637. pointShapeObj.other["region_attributes"]["id"] = pointShapeObj.id;
  1638. }
  1639. if (maxIdNum< parseInt(pointShapeObj.other["region_attributes"]["id"])){
  1640. maxIdNum = parseInt(pointShapeObj.other["region_attributes"]["id"]);
  1641. }
  1642. pointShapes.push(pointShapeObj);
  1643. }
  1644. }
  1645. //console.log(rects);
  1646. //console.log(masks);
  1647. }
  1648. document.getElementById("boxlabels").innerHTML=boxlabelshtml();
  1649. document.getElementById("labelcounttable").innerHTML=boxlabelcounthtml();
  1650. // 加载值:需要打开已有属性和属性值,需要回传_via_attributes, _via_img_metadata两个值的获取
  1651. //暂时默认设置只有类别属性
  1652. set_display_area_content( VIA_DISPLAY_AREA_CONTENT_NAME.IMAGE );
  1653. }
  1654. function getHtmlStr(shape,shapetype,rectIndex){
  1655. var lablebg="";
  1656. if (shape.isSelected){
  1657. lablebg=" style=\"background:#eee;color:#5a5a5a;\"";
  1658. var tmp = "tr_" + shapetype + "_" + Math.max(rectIndex-1,0);
  1659. var $objTr = $("#"+tmp) ; //找到要定位的地方 tr
  1660. var objTr = $objTr[0]; //转化为dom对象
  1661. if (!isEmpty(objTr)){
  1662. $("#labelpanel").animate({scrollTop:objTr.offsetTop},0); //滚动条滚动
  1663. }
  1664. }
  1665. var tmpType = shape.type;
  1666. //console.log("tmpType =" + tmpType);
  1667. if(!isEmpty(shape.other["region_attributes"]["type"])){
  1668. tmpType = shape.other["region_attributes"]["type"];
  1669. }
  1670. var shapeswidthHeigth = "";
  1671. if (shapetype == "bbox"){
  1672. xywh = shape.getXYWH();
  1673. shapeswidthHeigth = getRealLocationX(xywh[2]) + "," + getRealLocationY(xywh[3]);
  1674. }
  1675. var xy=shape.points;
  1676. var x ;
  1677. var y ;
  1678. if (shapetype == "point"){
  1679. x = shape.x;
  1680. y = shape.y;
  1681. }
  1682. else{
  1683. x = xy[0].x;
  1684. y = xy[0].y;
  1685. }
  1686. return "<tr id=\"tr_" + shapetype + "_" + rectIndex + "\" onclick=\"highlight("+x+","+y+", "+rectIndex+", '"+shapetype+"');\"" +lablebg + "><td style=\"width:10px\"></td> <td>"+ tmpType + "</td><td>" + shapetype + "</td><td>" + shapeswidthHeigth + "</td></tr>";
  1687. }
  1688. function setStyle(rectIndex,shapetype){
  1689. for (var i=0;i<rects.length;i++){
  1690. document.getElementById("tr_bbox_" + i).style = "";
  1691. }
  1692. for (var i=0;i<pointShapes.length;i++){
  1693. document.getElementById("tr_point_" + i).style = "";
  1694. }
  1695. for (var i=0;i<masks.length;i++){
  1696. document.getElementById("tr_mask_" + i).style = "";
  1697. }
  1698. document.getElementById("tr_" + shapetype + "_" + rectIndex).style = "background:#eee;color:#5a5a5a;";
  1699. }
  1700. function highlight(x,y,rectIndex,shapetype){
  1701. setStyle(rectIndex,shapetype);
  1702. Selectedmask = null;
  1703. SelectedRect = null;
  1704. SelectedPointShape = null;
  1705. if (shapetype=="bbox"){
  1706. for (var i=0;i<rects.length;i++){
  1707. rects[i].isSelected = false;
  1708. if (i==rectIndex){
  1709. rects[i].isSelected = true;
  1710. SelectedRect = rects[i];
  1711. }
  1712. }
  1713. for (var i=0;i<pointShapes.length;i++){
  1714. pointShapes[i].isSelected = false;
  1715. }
  1716. for (var i=0;i<masks.length;i++){
  1717. masks[i].isSelected = false;
  1718. }
  1719. }
  1720. else if (shapetype=="point"){
  1721. for (var i=0;i<rects.length;i++){
  1722. rects[i].isSelected = false;
  1723. }
  1724. for (var i=0;i<pointShapes.length;i++){
  1725. pointShapes[i].isSelected = false;
  1726. if (i==rectIndex){
  1727. pointShapes[i].isSelected = true;
  1728. SelectedPointShape = pointShapes[i];
  1729. }
  1730. }
  1731. for (var i=0;i<masks.length;i++){
  1732. masks[i].isSelected = false;
  1733. }
  1734. }
  1735. else{
  1736. SelectedRect = null;
  1737. for (var i=0;i<rects.length;i++){
  1738. rects[i].isSelected = false;
  1739. }
  1740. for (var i=0;i<pointShapes.length;i++){
  1741. pointShapes[i].isSelected = false;
  1742. }
  1743. for (var i=0;i<masks.length;i++){
  1744. masks[i].isSelected = false;
  1745. if (i==rectIndex){
  1746. masks[i].isSelected = true;
  1747. Selectedmask = masks[i];
  1748. }
  1749. }
  1750. }
  1751. drawRect();
  1752. }
  1753. function boxlabelshtml(){
  1754. var htmlstr="";
  1755. for (var i=0;i<rects.length;i++){
  1756. htmlstr = htmlstr + getHtmlStr(rects[i],'bbox',i);
  1757. }
  1758. for (var i=0;i<masks.length;i++){
  1759. htmlstr = htmlstr + getHtmlStr(masks[i],'mask',i);
  1760. }
  1761. for(var i = 0; i < pointShapes.length; i++){
  1762. htmlstr = htmlstr + getHtmlStr(pointShapes[i],'point',i);
  1763. }
  1764. return htmlstr;
  1765. }
  1766. function boxlabelCount(labelMap,shape){
  1767. var tmpType = shape.type;
  1768. if(!isEmpty(shape.other["region_attributes"]["type"])){
  1769. tmpType = shape.other["region_attributes"]["type"];
  1770. }
  1771. if(labelMap[tmpType] == null){
  1772. labelMap[tmpType] = 1;
  1773. }else{
  1774. labelMap[tmpType] = labelMap[tmpType] + 1;
  1775. }
  1776. }
  1777. function boxlabelcounthtml(){
  1778. var htmlstr="";
  1779. var labelMap = {};
  1780. for (var i=0;i<rects.length;i++){
  1781. boxlabelCount(labelMap,rects[i]);
  1782. }
  1783. for (var i=0;i<masks.length;i++){
  1784. boxlabelCount(labelMap,masks[i]);
  1785. }
  1786. for (var i=0;i<pointShapes.length;i++){
  1787. boxlabelCount(labelMap,pointShapes[i]);
  1788. }
  1789. for (item in labelMap){
  1790. htmlstr = htmlstr + "<tr><td style=\"width:10px\"></td> <td>"+ item + "</td><td>" + labelMap[item] +"</td></tr>";
  1791. }
  1792. return htmlstr;
  1793. }
  1794. function getRealLocationX(num){
  1795. var loc = Math.round(num*img.width/canvas.width);
  1796. // if (img.width<600){
  1797. // loc = Math.round(num);
  1798. // }
  1799. if(loc <= 0){
  1800. loc = 1;
  1801. }
  1802. if(loc > img.width){
  1803. loc = img.width -1;
  1804. }
  1805. return loc;
  1806. }
  1807. function getRealLocationY(num){
  1808. var loc = Math.round(num*img.height/canvas.height);
  1809. // if (img.width<600){
  1810. // loc = Math.round(num);
  1811. // }
  1812. if(loc <= 0){
  1813. loc = 1;
  1814. }
  1815. if( loc > img.height){
  1816. loc = img.height -1;
  1817. }
  1818. return loc;
  1819. }
  1820. function getCanvasLocationX(num){
  1821. return Math.round(num*canvas.width/parseInt(img.width));
  1822. }
  1823. function getCanvasLocationY(num){
  1824. return Math.round(num*canvas.height/parseInt(img.height));
  1825. }
  1826. function setAutoModel(){
  1827. hidePopup();
  1828. loadModel();
  1829. display_createlabel();
  1830. }
  1831. var algModelList;
  1832. function loadModel(){
  1833. $.ajax({
  1834. type:"GET",
  1835. contentType:'application/json',
  1836. url: ip + "/api/queryAlgModelForHandLabel/",
  1837. dataType:"json",
  1838. async:false,
  1839. headers: {
  1840. // Accept: "text/html; q=1.0",
  1841. authorization:token,
  1842. },
  1843. // enctype:"multipart/form-data",
  1844. success:function(jsonList){
  1845. console.log(jsonList);
  1846. algModelList = jsonList;
  1847. // return json.token;
  1848. },
  1849. error:function(response) {
  1850. redirect(response);
  1851. }
  1852. });
  1853. }
  1854. function display_createlabel(){
  1855. var html="<option value=\"\" selected=\"\">请选择</option>";
  1856. for (var i=0;i<algModelList.length;i++){
  1857. if (i==2){
  1858. var row = "<option selected value=\""+algModelList[i].id+
  1859. "\">"+algModelList[i].model_name+
  1860. "</option>";
  1861. }
  1862. else{
  1863. var row = "<option value=\""+algModelList[i].id+
  1864. "\">"+algModelList[i].model_name+
  1865. "</option>";
  1866. }
  1867. html=html+row;
  1868. }
  1869. console.log(html);
  1870. $('#tracking_startid').val('1');
  1871. $('#tracking_endid').val(tablePageData.total);
  1872. document.getElementById('predict_model').innerHTML=html;
  1873. document.getElementById("tracking_startid_div").style.display="none";
  1874. document.getElementById("tracking_endid_div").style.display="none";
  1875. document.getElementById("label_id_div").style.display="none";
  1876. document.getElementById("labelOption_div").style.display="none";
  1877. //document.getElementById("labelOption").innerHTML="<option value=\"2\" selected=\"\">请选择</option> <option value=\"3\">识别车的类型与颜色</option>";
  1878. document.getElementById('predtask_id').disabled=false;
  1879. $('#label_id').val('1');
  1880. bar.style.width='1%';
  1881. document.getElementById('text-progress').innerHTML='0%';
  1882. }
  1883. function submit_predtask(){
  1884. var item_id = labeltastresult[fileindex].id;
  1885. var predict_model_val = $('#predict_model').val();
  1886. if(isEmpty(predict_model_val)){
  1887. alert("请选择标注任务使用的模型。");
  1888. return;
  1889. }
  1890. if(labeltastresult[fileindex].label_status == 0 && !(predict_model_val == 12 || predict_model_val == 16 || predict_model_val == 20 || predict_model_val == 21)){
  1891. alert("标注状态已经完成,不能进行自动检测。");
  1892. return;
  1893. }
  1894. var task_type = "1";
  1895. var start_id = 0;
  1896. var end_id = 0;
  1897. var label_id = 1;
  1898. var label_option = null;
  1899. if(predict_model_val == 12 || predict_model_val == 16 || predict_model_val == 20 || predict_model_val == 21){
  1900. task_type = "2";
  1901. start_id = $('#tracking_startid').val();
  1902. end_id = $('#tracking_endid').val();
  1903. label_id = $('#label_id').val();
  1904. if(start_id < 1 || start_id > tablePageData.total){
  1905. alert("请输入正确的追踪起始图片ID,范围为1到" + tablePageData.total);
  1906. return;
  1907. }
  1908. if(end_id < 1 || end_id > tablePageData.total){
  1909. alert("请输入正确的追踪结束图片ID,范围为1到" + tablePageData.total);
  1910. return;
  1911. }
  1912. if(label_id < 1){
  1913. alert("标注框ID为大于等于1的整数。");
  1914. return;
  1915. }
  1916. }
  1917. document.getElementById('predtask_id').disabled=true;
  1918. $.ajax({
  1919. type:"POST",
  1920. url:ip + "/gitea/auto-label-task",
  1921. contentType:'application/json',
  1922. headers: {
  1923. authorization:token,
  1924. },
  1925. dataType:"json",
  1926. async:false,
  1927. data:JSON.stringify({'label_task_id':item_id,
  1928. 'model':predict_model_val,
  1929. 'pic_object_name' : img.width + "," + img.height,
  1930. 'task_type':task_type,
  1931. 'startIndex':start_id,
  1932. 'endIndex':end_id,
  1933. 'taskId':label_task,
  1934. 'label_id':label_id,
  1935. 'label_option':label_option
  1936. }),
  1937. success:function(res){
  1938. console.log('创建数据信息');
  1939. },
  1940. error:function(response) {
  1941. redirect(response);
  1942. }
  1943. });
  1944. setIntervalToDo();
  1945. }
  1946. var timeId;
  1947. var count;
  1948. var progress;
  1949. function setIntervalToDo(){
  1950. count=0;
  1951. timeId = self.setInterval("clock()",1000);//5秒刷新
  1952. console.log("开始刷新。timeId=" + timeId);
  1953. }
  1954. function clock(){
  1955. count++;
  1956. if(count > 600 ){
  1957. console.log("清除定时器。timeId=" + timeId);
  1958. window.clearInterval(timeId);
  1959. timeId = null;
  1960. $("#autoLabel").modal('hide');
  1961. return;
  1962. }
  1963. $.ajax({
  1964. type:"GET",
  1965. url:ip + "/api/query-auto-label-task-progress/",
  1966. headers: {
  1967. authorization:token,
  1968. },
  1969. dataType:"json",
  1970. data:{'taskId': label_task},
  1971. async:false,
  1972. success:function(json){
  1973. progress = json;
  1974. console.log(json);
  1975. },
  1976. error:function(response) {
  1977. progress = null;
  1978. console.log("query progress error");
  1979. redirect(response);
  1980. }
  1981. });
  1982. if(isEmpty(progress)){
  1983. console.log("清除定时器。timeId=" + timeId);
  1984. bar.style.width='100%';
  1985. document.getElementById('text-progress').innerHTML='100%';
  1986. window.clearInterval(timeId);
  1987. timeId = null;
  1988. var current = $('#displayPage1').text();
  1989. $("#autoLabel").modal('hide');
  1990. console.log("开始获取结果。current=" + current);
  1991. if(current >= 1){
  1992. pageReload(current - 1,pageSize,fileindex);
  1993. }
  1994. }else{
  1995. //更新进度
  1996. var iSpeed = progress.progress;
  1997. bar.style.width=iSpeed+'%';
  1998. document.getElementById('text-progress').innerHTML=iSpeed+'%'
  1999. }
  2000. /*
  2001. var current = $('#displayPage1').text();
  2002. console.log("开始刷新。current=" + current);
  2003. if(current >= 1){
  2004. pageReload(current - 1,pageSize,fileindex);
  2005. if(!isEmpty(labeltastresult[fileindex].label_info)){
  2006. window.clearInterval(timeId);
  2007. timeId = null;
  2008. }
  2009. }
  2010. */
  2011. }
  2012. function submit_deletelabel(){
  2013. var start_id = $('#delete_startid').val();
  2014. var end_id = $('#delete_endid').val();
  2015. if(start_id < 1 || start_id > tablePageData.total){
  2016. alert("请输入正确的起始图片ID,范围为1到" + tablePageData.total);
  2017. return;
  2018. }
  2019. if(end_id < 1 || end_id > tablePageData.total){
  2020. alert("请输入正确的结束图片ID,范围为1到" + tablePageData.total);
  2021. return;
  2022. }
  2023. //var one_reid_name = $('#one_reid_name').val();
  2024. $.ajax({
  2025. type:"POST",
  2026. url:ip + "/gitea/label-task-delete-label",
  2027. headers: {
  2028. authorization:token,
  2029. },
  2030. dataType:"json",
  2031. async:false,
  2032. data:{'label_task_id':label_task_info.id,
  2033. 'start_id':start_id,
  2034. 'end_id' : end_id
  2035. //'one_reid_name':one_reid_name
  2036. },
  2037. success:function(res){
  2038. console.log('创建数据信息');
  2039. },
  2040. error:function(response) {
  2041. redirect(response);
  2042. }
  2043. });
  2044. $("#deleteLabel").modal('hide');
  2045. var current = $('#displayPage1').text();
  2046. if(current >= 1){
  2047. pageReload(current - 1,pageSize,fileindex);
  2048. }
  2049. }
  2050. function updatelabel(fileindex){
  2051. var label_list=[]
  2052. for (var i=0;i<rects.length;i++){
  2053. x1y1x2y2=rects[i].getX1Y1X2Y2();
  2054. rects[i].type = '';//regions[i].other.["region_attributes"]["type"];
  2055. var label= {'class_name':rects[i].type, "score":1.0};
  2056. if(!isEmpty(rects[i].other.region_attributes.type)){
  2057. label['class_name'] = rects[i].other.region_attributes.type;
  2058. }
  2059. if(!isEmpty(rects[i].other.region_attributes.id)){
  2060. rects[i].id = rects[i].other.region_attributes.id;
  2061. }
  2062. var xmin = getRealLocationX(x1y1x2y2[0]);
  2063. var ymin = getRealLocationY(x1y1x2y2[1]);
  2064. var xmax = getRealLocationX(x1y1x2y2[2]);
  2065. var ymax = getRealLocationY(x1y1x2y2[3]);
  2066. label['box']=[xmin,ymin, xmax,ymax];
  2067. if(isEmpty(rects[i].id)){
  2068. label['id'] = i+'';
  2069. }else{
  2070. label['id'] = rects[i].id+'';
  2071. }
  2072. label['blurred']=rects[i].blurred;
  2073. label['goodIllumination']=rects[i].goodIllumination;
  2074. label['frontview']=rects[i].frontview;
  2075. label['other']=rects[i].other;
  2076. //console.log(label);
  2077. label_list.push(label);
  2078. }
  2079. for (var i=0;i<masks.length;i++){
  2080. masks[i].type = '';//regions[i].other.["region_attributes"]["type"];
  2081. var label = {'class_name':masks[i].type, "score":1.0};
  2082. if(!isEmpty(masks[i].other.region_attributes.type)){
  2083. label['class_name'] = masks[i].other.region_attributes.type;
  2084. }
  2085. if(!isEmpty(masks[i].other.region_attributes.id)){
  2086. masks[i].id = masks[i].other.region_attributes.id;
  2087. }
  2088. var labelMaskList = [];
  2089. for(var j = 0; j < masks[i].points.length; j++){
  2090. labelMaskList.push(getRealLocationX(masks[i].points[j].x));
  2091. labelMaskList.push(getRealLocationY(masks[i].points[j].y));
  2092. }
  2093. label['mask'] = labelMaskList;
  2094. label['id'] = masks[i].id+'';
  2095. label['blurred']=masks[i].blurred;
  2096. label['goodIllumination']=masks[i].goodIllumination;
  2097. label['frontview']=masks[i].frontview;
  2098. label['other']=masks[i].other;
  2099. //console.log(label);
  2100. label_list.push(label);
  2101. }
  2102. for (var i=0;i<pointShapes.length;i++){
  2103. pointShapes[i].type = '';//regions[i].other.["region_attributes"]["type"];
  2104. var label = {'class_name':pointShapes[i].type, "score":1.0};
  2105. if(!isEmpty(pointShapes[i].other.region_attributes.type)){
  2106. label['class_name'] = pointShapes[i].other.region_attributes.type;
  2107. }
  2108. if(!isEmpty(pointShapes[i].other.region_attributes.id)){
  2109. pointShapes[i].id = pointShapes[i].other.region_attributes.id;
  2110. }
  2111. var pointList = [];
  2112. pointList.push(getRealLocationX(pointShapes[i].x));
  2113. pointList.push(getRealLocationY(pointShapes[i].y));
  2114. pointList.push(2);//0表示这个关键点没有标注(这种情况下x=y=v=0),1表示这个关键点标注了但是不可见(被遮挡了),2 表示这个关键点标注了同时也可见
  2115. label['keypoints'] = pointList;
  2116. label['id'] = pointShapes[i].id+'';
  2117. label['blurred']=pointShapes[i].blurred;
  2118. label['goodIllumination']=pointShapes[i].goodIllumination;
  2119. label['frontview']=pointShapes[i].frontview;
  2120. label['other']=pointShapes[i].other;
  2121. //console.log(label);
  2122. label_list.push(label);
  2123. }
  2124. labelinfo_jsonstr = JSON.stringify(label_list);
  2125. labeltastresult[fileindex].label_info=labelinfo_jsonstr;
  2126. var flag = 0;
  2127. if(isVerified()){
  2128. labeltastresult[fileindex].verify_status=1;
  2129. flag = 100;
  2130. }else{
  2131. if(label_list.length > 0){
  2132. labeltastresult[fileindex].label_status=0;
  2133. }
  2134. else{
  2135. labeltastresult[fileindex].label_status=1;
  2136. }
  2137. }
  2138. $.ajax({
  2139. type:"PATCH",
  2140. url:ip + "/gitea/label-task-item/",
  2141. contentType:'application/json',
  2142. headers: {
  2143. authorization:token,
  2144. },
  2145. dataType:"json",
  2146. async:false,
  2147. data:JSON.stringify({'id':labeltastresult[fileindex].id,
  2148. 'label_task_id':label_task_info.id,
  2149. 'label_info':labelinfo_jsonstr,
  2150. 'label_status': labeltastresult[fileindex].label_status,
  2151. 'verify_status': labeltastresult[fileindex].verify_status,
  2152. 'pic_object_name' : img.width + "," + img.height,
  2153. 'display_order2':flag
  2154. }),
  2155. success:function(json){
  2156. return true;
  2157. },
  2158. error:function(response) {
  2159. redirect(response);
  2160. }
  2161. });
  2162. return false;
  2163. }
  2164. function get_labeltask(){
  2165. console.log('query labeltask info.');
  2166. $.ajax({
  2167. type:"GET",
  2168. url:ip + "/gitea/label-task/"+label_task+"/",
  2169. headers: {
  2170. authorization:token,
  2171. },
  2172. dataType:"json",
  2173. async:false,
  2174. success:function(json){
  2175. label_task_info = json;
  2176. console.log('return labeltask info.' + label_task_info);
  2177. page(0,pageSize);
  2178. },
  2179. error:function(response) {
  2180. redirect(response);
  2181. }
  2182. });
  2183. }
  2184. function update_labeltask(task_label_type_info){
  2185. console.log("label_task_id=" + label_task_info.id);
  2186. console.log("task_label_type_info=" + task_label_type_info);
  2187. $.ajax({
  2188. type:"PATCH",
  2189. url:ip + "/gitea/label-task/",
  2190. headers: {
  2191. authorization:token,
  2192. },
  2193. dataType:"json",
  2194. data:{
  2195. 'label_task_id':label_task_info.id,
  2196. 'task_label_type_info':task_label_type_info,
  2197. },
  2198. async:false,
  2199. success:function(json){
  2200. console.log(json);
  2201. },
  2202. error:function(response) {
  2203. redirect(response);
  2204. }
  2205. });
  2206. }
  2207. function list(current,pageSize,index=0){
  2208. $.ajax({
  2209. type:"GET",
  2210. url:ip + "/gitea/label-task-item-page/",
  2211. headers: {
  2212. authorization:token,
  2213. },
  2214. dataType:"json",
  2215. data:{
  2216. 'label_task':label_task_info.id,
  2217. 'startPage':current,
  2218. 'pageSize':pageSize,
  2219. 'orderType': orderType,
  2220. 'findLast':findLast,
  2221. },
  2222. async:false,
  2223. success:function(json){
  2224. tablePageData = json;
  2225. tableData = json.data;
  2226. labeltastresult = tableData;
  2227. fileindex=index;
  2228. if(lastindex){
  2229. fileindex = pageSize - 1;
  2230. }
  2231. //console.log(json);
  2232. // return json.token;
  2233. },
  2234. error:function(response) {
  2235. redirect(response);
  2236. }
  2237. });
  2238. }
  2239. var pageSize = 20;
  2240. var tableData;
  2241. var tablePageData;
  2242. function pageReload(current,pageSize,fileindex){
  2243. list(current,pageSize,fileindex);
  2244. loadimg();
  2245. showtaskinfo();
  2246. showfilelist();
  2247. //display_list();
  2248. setPage(tablePageData,pageSize);
  2249. }
  2250. function page(current,pageSize){
  2251. list(current,pageSize);
  2252. loadimg();
  2253. showtaskinfo();
  2254. showfilelist();
  2255. //display_list();
  2256. setPage(tablePageData,pageSize);
  2257. }
  2258. function nextPage(){
  2259. hidePopup();
  2260. var current = $('#displayPage1').text();
  2261. console.log("current=" + current);
  2262. findLast = 0;
  2263. page(current,pageSize);
  2264. }
  2265. function prePage(){
  2266. hidePopup();
  2267. var current =$('#displayPage1').text();
  2268. console.log("current=" + current);
  2269. if(current > 1){
  2270. console.log("current=" + (current - 2));
  2271. findLast = 0;
  2272. page(current - 2,pageSize);
  2273. }
  2274. }
  2275. function goPage(){
  2276. hidePopup();
  2277. var goNum = $('#goNum').val();
  2278. findLast = 0;
  2279. var pageTotal = $("#totalNum").text();
  2280. var pageNum = parseInt(pageTotal/pageSize);
  2281. if(pageTotal%pageSize!=0){
  2282. pageNum += 1;
  2283. }else {
  2284. pageNum = pageNum;
  2285. }
  2286. if (goNum<=0){
  2287. alert("请输入大于0的数值");
  2288. }
  2289. else if(goNum<=pageNum){
  2290. page(goNum - 1,pageSize);
  2291. }
  2292. else{
  2293. alert("不能超出总页码!");
  2294. }
  2295. }
  2296. $("#goNum").keydown(function (e) {
  2297. if (e.keyCode == 13) {
  2298. goPage();
  2299. }
  2300. });
  2301. function setPage(pageData,pageSize){
  2302. var startIndex = pageData.current * pageSize;
  2303. if(startIndex < 10){
  2304. $('#startIndex').text(" " + (pageData.current * pageSize + 1));
  2305. }else{
  2306. $('#startIndex').text(pageData.current * pageSize + 1);
  2307. }
  2308. var endIndex = pageData.current * pageSize + pageData.data.length;
  2309. if(endIndex < 10){
  2310. $('#endIndex').text(" " + (pageData.current * pageSize + pageData.data.length));
  2311. }else{
  2312. $('#endIndex').text(pageData.current * pageSize + pageData.data.length);
  2313. }
  2314. $('#totalNum').text(pageData.total);
  2315. $('#displayPage1').text(pageData.current + 1);
  2316. console.log("set prePage status, pageData.current=" + pageData.current);
  2317. if(pageData.current == 0){
  2318. console.log("set prePage disabled.");
  2319. $('#prePage').removeAttr("href");
  2320. $('#prePage').attr('style','color:#000;margin-right:1em;');
  2321. }
  2322. else{
  2323. $('#prePage').attr("href","javascript:prePage()");
  2324. $('#prePage').attr('style','color:#f5f5f6;margin-right:1em;');
  2325. }
  2326. if((pageData.current + 1) * pageSize >= pageData.total){
  2327. console.log("set nextPage disabled.");
  2328. $('#nextPage').removeAttr("href");
  2329. $('#nextPage').attr('style','color:#000;margin-left:1em;')
  2330. }
  2331. else{
  2332. $('#nextPage').attr("href","javascript:nextPage()");
  2333. $('#nextPage').attr('style','color:#f5f5f6;margin-left:1em;');
  2334. }
  2335. var pageTotal = pageData.total;
  2336. var pageNum = parseInt(pageTotal/pageSize);
  2337. if(pageTotal%pageSize!=0){
  2338. pageNum += 1;
  2339. }else {
  2340. pageNum = pageNum;
  2341. }
  2342. $("#totalPageNum").text(pageNum);
  2343. }
  2344. init_index();
  2345. // canvas = document.getElementById("myCanvas");
  2346. // context = canvas.getContext("2d");
  2347. // var maxWidth = document.getElementById("showPic").offsetWidth;
  2348. // var maxHeight = document.getElementById("showPic").offsetHeight-100;
  2349. // canvas.width = maxWidth;//document.getElementById("tool0").offsetWidth;
  2350. // canvas.height = maxHeight;//document.getElementById("tool0").offsetWidth/1280*720;
  2351. // show_region = document.getElementById("show_region");
  2352. // show_region.width =document.getElementById("tool0").offsetWidth;
  2353. // show_region.height = document.getElementById("tool0").offsetWidth/1280*720;
  2354. function init_index() {
  2355. canvas = document.getElementById("myCanvas");
  2356. context = canvas.getContext("2d");
  2357. maxWidth = document.getElementById("showPic").offsetWidth;
  2358. maxHeight = document.getElementById("showPic").offsetHeight-100;
  2359. canvas.width = maxWidth;
  2360. canvas.height = maxHeight;
  2361. canvas.onmousedown = canvasClick;
  2362. canvas.onmouseup = stopDragging;
  2363. canvas.onmouseout = stopDragging;
  2364. canvas.onmousemove =dragRect;
  2365. var token = getSessionStorageMessage("token");
  2366. console.log("page load token=" + token);
  2367. if(!isEmpty(token)){
  2368. console.log("this is not null.token =" + token);
  2369. doLoad();
  2370. }
  2371. };
  2372. function doLoad(){
  2373. token = getSessionStorageMessage("token");
  2374. userType = getSessionStorageMessage("userType");
  2375. if(typeof token == "undefined" || token == null || token == ""){
  2376. console.log("token=" + token);
  2377. console.log("onload tasks/detect/index.html");
  2378. window.location.href = "../../login.html";
  2379. }
  2380. label_task = getSessionStorageMessage("label_task");
  2381. label_task_status = getSessionStorageMessage("label_task_status"); //1表示审核
  2382. get_labeltask();
  2383. drawRect();
  2384. _via_init();
  2385. //加载保存好的属性结构,如果不存在,加载默认的类别信息
  2386. if(!isEmpty(label_task_info.task_label_type_info)){
  2387. label_attributes = JSON.parse(label_task_info.task_label_type_info);
  2388. }
  2389. if (isEmpty(label_attributes)){
  2390. get_init_atrribute();
  2391. }
  2392. else{
  2393. if (Object.keys(label_attributes).length == 0){
  2394. get_init_atrribute();
  2395. }
  2396. else{
  2397. _via_attributes["region"] = label_attributes;
  2398. }
  2399. }
  2400. }
  2401. function get_init_atrribute(){
  2402. _via_attributes = {'region':{}};
  2403. var atti = "id"; // 属性名
  2404. _via_attributes['region'][atti] = {};
  2405. _via_attributes['region'][atti]["type"] = "text";
  2406. _via_attributes['region'][atti]["description"] = "";
  2407. _via_attributes['region'][atti]["default_value"] = "";
  2408. atti = "type"; // 属性名
  2409. _via_attributes['region'][atti] = {};
  2410. _via_attributes['region'][atti]["type"] = "dropdown";
  2411. _via_attributes['region'][atti]["description"] = "";
  2412. _via_attributes['region'][atti]["options"] = {};
  2413. _via_attributes['region'][atti]["options"]["car"] = "car";
  2414. _via_attributes['region'][atti]["options"]["person"] = "person";
  2415. _via_attributes['region'][atti]["options"]["non-motor"] = "non-motor";
  2416. _via_attributes['region'][atti]["default_options"] = {};
  2417. }
  2418. function model_sele_Change(event){
  2419. var modelid = $('#predict_model option:selected').val();
  2420. console.log("predict_model=" + modelid);
  2421. if(modelid == 12 || modelid == 16 || modelid == 20 || modelid == 21){
  2422. document.getElementById("tracking_startid_div").style.display="block";
  2423. document.getElementById("tracking_endid_div").style.display="block";
  2424. document.getElementById("labelOption_div").style.display="block";
  2425. if(modelid == 12 || modelid == 16){
  2426. document.getElementById("label_id_div").style.display="block";
  2427. }else{
  2428. document.getElementById("label_id_div").style.display="none";
  2429. }
  2430. if(modelid == 21){
  2431. document.getElementById("labelOption").innerHTML="<option value=\"10\" selected=\"\">person</option> <option value=\"11\">car</option>";
  2432. }else if(modelid == 20){
  2433. document.getElementById("labelOption").innerHTML="<option value=\"10\" selected=\"\">person</option>";
  2434. }else{
  2435. document.getElementById("labelOption").innerHTML="<option value=\"0\" selected=\"\">合并已有的标注信息</option> <option value=\"1\">删除已有的标注信息</option>";
  2436. }
  2437. }else{
  2438. document.getElementById("tracking_startid_div").style.display="none";
  2439. document.getElementById("tracking_endid_div").style.display="none";
  2440. document.getElementById("label_id_div").style.display="none";
  2441. document.getElementById("labelOption_div").style.display="none";
  2442. if(modelid == 5 || modelid == 6 || modelid == 7 ){
  2443. //document.getElementById("labelOption").innerHTML="<option value=\"2\" selected=\"\">请选择</option> <option value=\"3\">识别车的类型与颜色</option>";
  2444. }
  2445. }
  2446. }
  2447. function export_attribute(){
  2448. var url = ip + "/api/task-export-label-property/";
  2449. var $iframe = $('<iframe />');
  2450. var $form = $('<form method="get" target="_self"/>');
  2451. $form.attr('action', url); //设置get的url地址
  2452. $form.append('<input type="hidden" name="task_id" value="' + label_task + '" />');
  2453. $form.append('<input type="hidden" name="type" value="labeltask" />');
  2454. $iframe.append($form);
  2455. $(document.body).append($iframe);
  2456. $form[0].submit();//提交表单
  2457. $iframe.remove();//移除框架
  2458. }
  2459. function import_attribute(){
  2460. $('#datasetModal').modal('show');
  2461. }
  2462. function submit_import_property(){
  2463. var jsonContent = $("#jsoninput").val();
  2464. if(!isJSON(jsonContent)){
  2465. alert("输入格式非法。");
  2466. return;
  2467. }
  2468. $.ajax({
  2469. type:"POST",
  2470. url:ip + "/api/task-import-label-property/",
  2471. headers: {
  2472. authorization:token,
  2473. },
  2474. dataType:"json",
  2475. data:{
  2476. 'jsonContent':jsonContent,
  2477. 'taskType':"labeltask",
  2478. 'taskId':label_task
  2479. },
  2480. async:false,
  2481. success:function(json){
  2482. console.log(json);
  2483. },
  2484. error:function(response) {
  2485. redirect(response);
  2486. }
  2487. });
  2488. $('#datasetModal').modal('hide');
  2489. close_attribute();
  2490. }
  2491. function isJSON(str) {
  2492. if (typeof str == 'string') {
  2493. try {
  2494. var obj=JSON.parse(str);
  2495. if(typeof obj == 'object' && obj ){
  2496. return true;
  2497. }else{
  2498. return false;
  2499. }
  2500. } catch(e) {
  2501. console.log('error:'+str+'!!!'+e);
  2502. return false;
  2503. }
  2504. }
  2505. console.log('It is not a string!');
  2506. return false;
  2507. }
  2508. img.onload = function(){
  2509. loadFinished = false;
  2510. // 初始设置画布大小,最大值宽和高
  2511. canvas.width = maxWidth;//document.getElementById("tool0").offsetWidth;
  2512. canvas.height = maxHeight;//document.getElementById("tool0").offsetWidth/1280*720;
  2513. //调整画布大小
  2514. if ((img.width/img.height)<(canvas.width/canvas.height)){
  2515. canvas.width=canvas.height * img.width / img.height;
  2516. }
  2517. else{
  2518. canvas.height=canvas.width * img.height / img.width;
  2519. }
  2520. maxIdNum=0;
  2521. parse_labelinfo(labeltastresult[fileindex].label_info);
  2522. drawRect();
  2523. $('#filepanel').slimScroll({
  2524. alwaysVisible: true, //是否 始终显示组件(未更改库文件时,鼠标移开滚动条消失)
  2525. });
  2526. canvas.onmousewheel = canvas.onwheel = function (event) { //滚轮放大缩小
  2527. console.log("primivate x,y=" + event.clientX + "," + event.clientY);//鼠标在屏幕上的位置
  2528. event.wheelDelta = event.wheelDelta ? event.wheelDelta : (event.deltalY * (-40)); //获取当前鼠标的滚动情况
  2529. if (event.wheelDelta > 0) {// 放大
  2530. imgScale +=0.1;
  2531. console.log("imgScale=" + imgScale);
  2532. } else {// 缩小
  2533. imgScale -=0.1;
  2534. if(imgScale< 1) {//最小缩放1
  2535. imgScale = 1;
  2536. }
  2537. console.log("imgScale=" + imgScale);
  2538. }
  2539. drawRect(); //重新绘制图片
  2540. };
  2541. loadFinished=true;
  2542. };
  2543. document.onkeydown = function(e){
  2544. switch(e.keyCode){
  2545. case 37:
  2546. case 38:
  2547. case 39:
  2548. case 40:
  2549. e.preventDefault();
  2550. }
  2551. }
  2552. document.onkeyup=function(e){
  2553. console.log(e.keyCode)
  2554. console.log(window.event);
  2555. e=e||window.event;
  2556. e.preventDefault();
  2557. obj = e.srcElement||e.target;
  2558. if( obj != null && obj !=undefined ){
  2559. if(obj.type == "textarea" || obj.type=='text'){
  2560. //console.log("obj.type:"+obj.type);
  2561. return ;
  2562. }
  2563. }
  2564. switch(e.keyCode){
  2565. case 87: //W
  2566. // boxcls = classes;
  2567. createRectLabel();
  2568. break;
  2569. case 68:
  2570. deleterect();
  2571. break;
  2572. case 27:
  2573. cancel();
  2574. break;
  2575. case 83:
  2576. save();
  2577. break;
  2578. case 81:
  2579. last();
  2580. break;
  2581. case 69:
  2582. next();
  2583. break;
  2584. case 90://u
  2585. undo();
  2586. break;
  2587. case 67://c
  2588. copyOneBox();
  2589. break;
  2590. case 86://v
  2591. paste();
  2592. break;
  2593. case 37:
  2594. moveLeftSinglePx();
  2595. break;
  2596. case 38:
  2597. moveUpSinglePx();
  2598. break;
  2599. case 39:
  2600. moveRightSinglePx();
  2601. break;
  2602. case 40:
  2603. moveDownSinglePx();
  2604. break;
  2605. };
  2606. }