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
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947
  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. if(labeltastresult[i].pic_image_field.length > 70){
  1442. var tmpIndex = labeltastresult[i].pic_image_field.indexOf("/",70);
  1443. console.log(tmpIndex)
  1444. if(tmpIndex != -1){
  1445. fname = labeltastresult[i].pic_image_field.substring(tmpIndex + 1);
  1446. fname = fname.substring(fname.indexOf('/')+1);
  1447. }
  1448. }
  1449. var isfinished = labeltastresult[i].label_status;
  1450. if(isVerified()){
  1451. isfinished = labeltastresult[i].verify_status - 1;
  1452. }
  1453. var lablebg=" style=\"cursor:pointer\"";
  1454. var classStr = "style=\"color:#FF6200;background: transparent;border: 0;\"";
  1455. var finish="未完成";
  1456. if (isfinished=="0"){finish="已完成";classStr = "style=\"color:#27c24c;background: transparent;border: 0;\"";}
  1457. if (i==fileindex){lablebg=" style=\"color:#fff;cursor:pointer;\"";classStr = "style=\"color:#04B3E5;background: transparent;border: 0;\"";finish="标注中"}
  1458. if(isVerified()){
  1459. 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>";
  1460. }else{
  1461. 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>";
  1462. }
  1463. }
  1464. document.getElementById("filelist").innerHTML=htmlstr;
  1465. }
  1466. function changeStatus(i){
  1467. var tmpId='changeStatus_'+i;
  1468. var htmlstr= "<div class=\"panel\" style=\"background:#020004;border:0.5px solid #222324;margin-bottom:0;border-radius:0;\""
  1469. +">"
  1470. +"<label for=\"st\" style=\"padding:0.8em;color: #7092BE;\"> 标注状态修改为:</label>"+
  1471. "<select id="+tmpId+" name=\"标注状态\" style=\"text-align:center;border-radius:4px;margin-left: 1em;\">"+
  1472. "<option value=0 selected=\"\">已完成</option>"+
  1473. "<option value=1 >未完成</option>"+
  1474. "</select>"+
  1475. "<button onclick=\"updateStatus("+i+");\" class=\"btn\" style=\"padding:0;margin-left:3em;background: transparent;border:0;color:#04B3E5;\">提交</button>"
  1476. +"</div>"
  1477. document.getElementById("labelStatus").innerHTML=htmlstr;
  1478. }
  1479. // function changeStatus(i){
  1480. // var tmpId='changeStatus_'+i;
  1481. // var htmlstr= "<div class=\"panel\" style=background:#ffff;border: 1px solid rgba(0,0,0,0.2);border-radius: 6px;top:10px;"
  1482. // +">"
  1483. // +"<label for=\"st\" style=\"margin:15px;color:#333\"> 标注状态修改为:</label>"+
  1484. // "<select id="+tmpId+" name=\"标注状态\" style=\"width:100px;text-align:center;border-radius:4px;\">"+
  1485. // "<option value=0 selected=\"\">已完成</option>"+
  1486. // "<option value=1 >未完成</option>"+
  1487. // "</select>"+
  1488. // "<br />"+
  1489. // "<button onclick=\"updateStatus("+i+");\" class=\"btn btn-default\" style=\"margin:0 auto;display: block;border-radius:5px;width: 50px;\">提交</button>"
  1490. // +"</div>"
  1491. // document.getElementById("labelStatus").innerHTML=htmlstr;
  1492. // }
  1493. function changeVerifyStatus(i){
  1494. var tmpId='changeStatus_'+i;
  1495. var htmlstr= "<div class=\"panel\" style=background:#ffff;border: 1px solid rgba(0,0,0,0.2);border-radius: 6px;top:10px;"
  1496. +">"
  1497. +"<label for=\"st\" style=\"margin:15px;color:#333\"> 审核状态修改为:</label>"+
  1498. "<select id="+tmpId+" name=\"审核状态\" style=\"width:100px;text-align:center;border-radius:4px;\">"+
  1499. "<option value=1 selected=\"\">已完成</option>"+
  1500. "<option value=0 >未完成</option>"+
  1501. "</select>"+
  1502. "<br />"+
  1503. "<button onclick=\"updateVerifyStatus("+i+");\" class=\"btn btn-default\" style=\"margin:0 auto;display: block;border-radius:5px;width: 50px;\">提交</button>"
  1504. +"</div>"
  1505. document.getElementById("labelStatus").innerHTML=htmlstr;
  1506. }
  1507. function updateStatus(i){
  1508. var status_id = 'changeStatus_'+i;
  1509. var label_status=document.getElementById(status_id).value;
  1510. labeltastresult[fileindex].label_status = label_status;
  1511. $.ajax({
  1512. type:"PATCH",
  1513. url:ip + "/gitea/label-task-item-status/",
  1514. contentType:'application/json',
  1515. headers: {
  1516. authorization:token,
  1517. },
  1518. dataType:"json",
  1519. async:false,
  1520. data:JSON.stringify({'id':labeltastresult[fileindex].id,
  1521. 'label_task_id':label_task_info.id,
  1522. 'label_status':label_status,
  1523. }),
  1524. success:function(json){
  1525. showfilelist();
  1526. document.getElementById("labelStatus").innerHTML = "";
  1527. return true;
  1528. },
  1529. error:function(response) {
  1530. redirect(response);
  1531. }
  1532. });
  1533. }
  1534. function updateVerifyStatus(i){
  1535. var status_id = 'changeStatus_'+i;
  1536. var verify_status=document.getElementById(status_id).value;
  1537. labeltastresult[fileindex].verify_status = verify_status;
  1538. $.ajax({
  1539. type:"PATCH",
  1540. url:ip + "/gitea/label-task-item-verify-status/",
  1541. contentType:'application/json',
  1542. headers: {
  1543. authorization:token,
  1544. },
  1545. dataType:"json",
  1546. async:false,
  1547. data:JSON.stringify({'id':labeltastresult[fileindex].id,
  1548. 'label_task_id':label_task_info.id,
  1549. 'verify_status':verify_status,
  1550. }),
  1551. success:function(json){
  1552. showfilelist();
  1553. document.getElementById("labelStatus").innerHTML = "";
  1554. return true;
  1555. },
  1556. error:function(response) {
  1557. redirect(response);
  1558. }
  1559. });
  1560. }
  1561. //this.id =""; //标识
  1562. //this.blurred=false;//模糊不清的; 记不清的; 难以区分的; 模棱两可的
  1563. //this.goodIllumination = true; //照明
  1564. //this.frontview = true;//正面图
  1565. function parse_labelinfo(labelinfo){
  1566. rects.length = 0;
  1567. masks.length = 0;
  1568. pointShapes.length = 0;
  1569. if(!isEmpty(labelinfo)){
  1570. // console.log("标注信息:"+labelinfo);
  1571. var label_arr = JSON.parse(labelinfo);
  1572. for(var i=0;i<label_arr.length;i++){
  1573. if(!isEmpty(label_arr[i].mask)){
  1574. cls=label_arr[i].class_name;
  1575. var tmpMask = new maskar(getCanvasLocationX(label_arr[i].mask[0]),getCanvasLocationY(label_arr[i].mask[1]),cls);
  1576. for(var j = 2; j < label_arr[i].mask.length; j+=2){
  1577. tmpMask.points.push(new point(getCanvasLocationX(label_arr[i].mask[j]),getCanvasLocationY(label_arr[i].mask[j+1])));
  1578. }
  1579. if(!isEmpty(label_arr[i].id)){
  1580. tmpMask.id= label_arr[i].id;
  1581. }
  1582. if(!isEmpty(label_arr[i].blurred)){
  1583. tmpMask.blurred = label_arr[i].blurred;
  1584. }
  1585. if(!isEmpty(label_arr[i].goodIllumination)){
  1586. tmpMask.goodIllumination = label_arr[i].goodIllumination;
  1587. }
  1588. if(!isEmpty(label_arr[i].frontview)){
  1589. tmpMask.frontview = label_arr[i].frontview;
  1590. }
  1591. if(!isEmpty(label_arr[i].other)){
  1592. tmpMask.other = label_arr[i].other;
  1593. }else if (isEmpty(label_arr[i].other)){
  1594. tmpMask.other["region_attributes"]["type"] = tmpMask.type;
  1595. tmpMask.other["region_attributes"]["id"] = tmpMask.id;
  1596. }
  1597. tmpMask.finish = true;
  1598. if (maxIdNum< parseInt(tmpMask.other["region_attributes"]["id"])){
  1599. maxIdNum = parseInt(tmpMask.other["region_attributes"]["id"]);
  1600. }
  1601. masks.push(tmpMask);
  1602. }
  1603. else if(!isEmpty(label_arr[i].box)){
  1604. x1 = getCanvasLocationX(label_arr[i].box[0]);
  1605. y1 = getCanvasLocationY(label_arr[i].box[1]);
  1606. x2 = getCanvasLocationX(label_arr[i].box[2]);
  1607. y2 = getCanvasLocationY(label_arr[i].box[3]);
  1608. cls=label_arr[i].class_name;
  1609. score = label_arr[i].score;
  1610. var rect = new rectar(x1,y1,x2,y2,cls,score);
  1611. if(!isEmpty(label_arr[i].id)){
  1612. rect.id= label_arr[i].id;
  1613. }
  1614. if(!isEmpty(label_arr[i].blurred)){
  1615. rect.blurred = label_arr[i].blurred;
  1616. }
  1617. if(!isEmpty(label_arr[i].goodIllumination)){
  1618. rect.goodIllumination = label_arr[i].goodIllumination;
  1619. }
  1620. if(!isEmpty(label_arr[i].frontview)){
  1621. rect.frontview = label_arr[i].frontview;
  1622. }
  1623. if(!isEmpty(label_arr[i].other)){
  1624. rect.other = label_arr[i].other;
  1625. }
  1626. // else if (isEmpty(label_arr[i].other) && (isEmpty(label_attributes) || Object.keys(label_attributes).length == 0)){
  1627. else if (isEmpty(label_arr[i].other)){
  1628. rect.other["region_attributes"]["type"] = rect.type;
  1629. rect.other["region_attributes"]["id"] = rect.id;
  1630. }
  1631. if (maxIdNum< parseInt(rect.other["region_attributes"]["id"])){
  1632. maxIdNum = parseInt(rect.other["region_attributes"]["id"]);
  1633. }
  1634. rects.push(rect);
  1635. }
  1636. else if(!isEmpty(label_arr[i].keypoints)){
  1637. cls=label_arr[i].class_name;
  1638. score = label_arr[i].score;
  1639. var pointShapeObj = new pointShape(getCanvasLocationX(label_arr[i].keypoints[0]),getCanvasLocationY(label_arr[i].keypoints[1]),cls,score);
  1640. if(!isEmpty(label_arr[i].other)){
  1641. pointShapeObj.other = label_arr[i].other;
  1642. }
  1643. else if (isEmpty(label_arr[i].other)){
  1644. pointShapeObj.other["region_attributes"]["type"] = pointShapeObj.type;
  1645. pointShapeObj.other["region_attributes"]["id"] = pointShapeObj.id;
  1646. }
  1647. if (maxIdNum< parseInt(pointShapeObj.other["region_attributes"]["id"])){
  1648. maxIdNum = parseInt(pointShapeObj.other["region_attributes"]["id"]);
  1649. }
  1650. pointShapes.push(pointShapeObj);
  1651. }
  1652. }
  1653. //console.log(rects);
  1654. //console.log(masks);
  1655. }
  1656. document.getElementById("boxlabels").innerHTML=boxlabelshtml();
  1657. document.getElementById("labelcounttable").innerHTML=boxlabelcounthtml();
  1658. // 加载值:需要打开已有属性和属性值,需要回传_via_attributes, _via_img_metadata两个值的获取
  1659. //暂时默认设置只有类别属性
  1660. set_display_area_content( VIA_DISPLAY_AREA_CONTENT_NAME.IMAGE );
  1661. }
  1662. function getHtmlStr(shape,shapetype,rectIndex){
  1663. var lablebg="";
  1664. if (shape.isSelected){
  1665. lablebg=" style=\"background:#eee;color:#5a5a5a;\"";
  1666. var tmp = "tr_" + shapetype + "_" + Math.max(rectIndex-1,0);
  1667. var $objTr = $("#"+tmp) ; //找到要定位的地方 tr
  1668. var objTr = $objTr[0]; //转化为dom对象
  1669. if (!isEmpty(objTr)){
  1670. $("#labelpanel").animate({scrollTop:objTr.offsetTop},0); //滚动条滚动
  1671. }
  1672. }
  1673. var tmpType = shape.type;
  1674. //console.log("tmpType =" + tmpType);
  1675. if(!isEmpty(shape.other["region_attributes"]["type"])){
  1676. tmpType = shape.other["region_attributes"]["type"];
  1677. }
  1678. var shapeswidthHeigth = "";
  1679. if (shapetype == "bbox"){
  1680. xywh = shape.getXYWH();
  1681. shapeswidthHeigth = getRealLocationX(xywh[2]) + "," + getRealLocationY(xywh[3]);
  1682. }
  1683. var xy=shape.points;
  1684. var x ;
  1685. var y ;
  1686. if (shapetype == "point"){
  1687. x = shape.x;
  1688. y = shape.y;
  1689. }
  1690. else{
  1691. x = xy[0].x;
  1692. y = xy[0].y;
  1693. }
  1694. 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>";
  1695. }
  1696. function setStyle(rectIndex,shapetype){
  1697. for (var i=0;i<rects.length;i++){
  1698. document.getElementById("tr_bbox_" + i).style = "";
  1699. }
  1700. for (var i=0;i<pointShapes.length;i++){
  1701. document.getElementById("tr_point_" + i).style = "";
  1702. }
  1703. for (var i=0;i<masks.length;i++){
  1704. document.getElementById("tr_mask_" + i).style = "";
  1705. }
  1706. document.getElementById("tr_" + shapetype + "_" + rectIndex).style = "background:#eee;color:#5a5a5a;";
  1707. }
  1708. function highlight(x,y,rectIndex,shapetype){
  1709. setStyle(rectIndex,shapetype);
  1710. Selectedmask = null;
  1711. SelectedRect = null;
  1712. SelectedPointShape = null;
  1713. if (shapetype=="bbox"){
  1714. for (var i=0;i<rects.length;i++){
  1715. rects[i].isSelected = false;
  1716. if (i==rectIndex){
  1717. rects[i].isSelected = true;
  1718. SelectedRect = rects[i];
  1719. }
  1720. }
  1721. for (var i=0;i<pointShapes.length;i++){
  1722. pointShapes[i].isSelected = false;
  1723. }
  1724. for (var i=0;i<masks.length;i++){
  1725. masks[i].isSelected = false;
  1726. }
  1727. }
  1728. else if (shapetype=="point"){
  1729. for (var i=0;i<rects.length;i++){
  1730. rects[i].isSelected = false;
  1731. }
  1732. for (var i=0;i<pointShapes.length;i++){
  1733. pointShapes[i].isSelected = false;
  1734. if (i==rectIndex){
  1735. pointShapes[i].isSelected = true;
  1736. SelectedPointShape = pointShapes[i];
  1737. }
  1738. }
  1739. for (var i=0;i<masks.length;i++){
  1740. masks[i].isSelected = false;
  1741. }
  1742. }
  1743. else{
  1744. SelectedRect = null;
  1745. for (var i=0;i<rects.length;i++){
  1746. rects[i].isSelected = false;
  1747. }
  1748. for (var i=0;i<pointShapes.length;i++){
  1749. pointShapes[i].isSelected = false;
  1750. }
  1751. for (var i=0;i<masks.length;i++){
  1752. masks[i].isSelected = false;
  1753. if (i==rectIndex){
  1754. masks[i].isSelected = true;
  1755. Selectedmask = masks[i];
  1756. }
  1757. }
  1758. }
  1759. drawRect();
  1760. }
  1761. function boxlabelshtml(){
  1762. var htmlstr="";
  1763. for (var i=0;i<rects.length;i++){
  1764. htmlstr = htmlstr + getHtmlStr(rects[i],'bbox',i);
  1765. }
  1766. for (var i=0;i<masks.length;i++){
  1767. htmlstr = htmlstr + getHtmlStr(masks[i],'mask',i);
  1768. }
  1769. for(var i = 0; i < pointShapes.length; i++){
  1770. htmlstr = htmlstr + getHtmlStr(pointShapes[i],'point',i);
  1771. }
  1772. return htmlstr;
  1773. }
  1774. function boxlabelCount(labelMap,shape){
  1775. var tmpType = shape.type;
  1776. if(!isEmpty(shape.other["region_attributes"]["type"])){
  1777. tmpType = shape.other["region_attributes"]["type"];
  1778. }
  1779. if(labelMap[tmpType] == null){
  1780. labelMap[tmpType] = 1;
  1781. }else{
  1782. labelMap[tmpType] = labelMap[tmpType] + 1;
  1783. }
  1784. }
  1785. function boxlabelcounthtml(){
  1786. var htmlstr="";
  1787. var labelMap = {};
  1788. for (var i=0;i<rects.length;i++){
  1789. boxlabelCount(labelMap,rects[i]);
  1790. }
  1791. for (var i=0;i<masks.length;i++){
  1792. boxlabelCount(labelMap,masks[i]);
  1793. }
  1794. for (var i=0;i<pointShapes.length;i++){
  1795. boxlabelCount(labelMap,pointShapes[i]);
  1796. }
  1797. for (item in labelMap){
  1798. htmlstr = htmlstr + "<tr><td style=\"width:10px\"></td> <td>"+ item + "</td><td>" + labelMap[item] +"</td></tr>";
  1799. }
  1800. return htmlstr;
  1801. }
  1802. function getRealLocationX(num){
  1803. var loc = Math.round(num*img.width/canvas.width);
  1804. // if (img.width<600){
  1805. // loc = Math.round(num);
  1806. // }
  1807. if(loc <= 0){
  1808. loc = 1;
  1809. }
  1810. if(loc > img.width){
  1811. loc = img.width -1;
  1812. }
  1813. return loc;
  1814. }
  1815. function getRealLocationY(num){
  1816. var loc = Math.round(num*img.height/canvas.height);
  1817. // if (img.width<600){
  1818. // loc = Math.round(num);
  1819. // }
  1820. if(loc <= 0){
  1821. loc = 1;
  1822. }
  1823. if( loc > img.height){
  1824. loc = img.height -1;
  1825. }
  1826. return loc;
  1827. }
  1828. function getCanvasLocationX(num){
  1829. return Math.round(num*canvas.width/parseInt(img.width));
  1830. }
  1831. function getCanvasLocationY(num){
  1832. return Math.round(num*canvas.height/parseInt(img.height));
  1833. }
  1834. function setAutoModel(){
  1835. hidePopup();
  1836. loadModel();
  1837. display_createlabel();
  1838. }
  1839. var algModelList;
  1840. function loadModel(){
  1841. $.ajax({
  1842. type:"GET",
  1843. contentType:'application/json',
  1844. url: ip + "/api/queryAlgModelForHandLabel/",
  1845. dataType:"json",
  1846. async:false,
  1847. headers: {
  1848. // Accept: "text/html; q=1.0",
  1849. authorization:token,
  1850. },
  1851. // enctype:"multipart/form-data",
  1852. success:function(jsonList){
  1853. console.log(jsonList);
  1854. algModelList = jsonList;
  1855. // return json.token;
  1856. },
  1857. error:function(response) {
  1858. redirect(response);
  1859. }
  1860. });
  1861. }
  1862. function display_createlabel(){
  1863. var html="<option value=\"\" selected=\"\">请选择</option>";
  1864. for (var i=0;i<algModelList.length;i++){
  1865. if (i==2){
  1866. var row = "<option selected value=\""+algModelList[i].id+
  1867. "\">"+algModelList[i].model_name+
  1868. "</option>";
  1869. }
  1870. else{
  1871. var row = "<option value=\""+algModelList[i].id+
  1872. "\">"+algModelList[i].model_name+
  1873. "</option>";
  1874. }
  1875. html=html+row;
  1876. }
  1877. console.log(html);
  1878. $('#tracking_startid').val('1');
  1879. $('#tracking_endid').val(tablePageData.total);
  1880. document.getElementById('predict_model').innerHTML=html;
  1881. document.getElementById("tracking_startid_div").style.display="none";
  1882. document.getElementById("tracking_endid_div").style.display="none";
  1883. document.getElementById("label_id_div").style.display="none";
  1884. document.getElementById("labelOption_div").style.display="none";
  1885. //document.getElementById("labelOption").innerHTML="<option value=\"2\" selected=\"\">请选择</option> <option value=\"3\">识别车的类型与颜色</option>";
  1886. document.getElementById('predtask_id').disabled=false;
  1887. $('#label_id').val('1');
  1888. bar.style.width='1%';
  1889. document.getElementById('text-progress').innerHTML='0%';
  1890. }
  1891. function submit_predtask(){
  1892. var item_id = labeltastresult[fileindex].id;
  1893. var predict_model_val = $('#predict_model').val();
  1894. if(isEmpty(predict_model_val)){
  1895. alert("请选择标注任务使用的模型。");
  1896. return;
  1897. }
  1898. if(labeltastresult[fileindex].label_status == 0 && !(predict_model_val == 12 || predict_model_val == 16 || predict_model_val == 20 || predict_model_val == 21)){
  1899. alert("标注状态已经完成,不能进行自动检测。");
  1900. return;
  1901. }
  1902. var task_type = "1";
  1903. var start_id = 0;
  1904. var end_id = 0;
  1905. var label_id = 1;
  1906. var label_option = null;
  1907. if(predict_model_val == 12 || predict_model_val == 16 || predict_model_val == 20 || predict_model_val == 21){
  1908. task_type = "2";
  1909. start_id = $('#tracking_startid').val();
  1910. end_id = $('#tracking_endid').val();
  1911. label_id = $('#label_id').val();
  1912. if(start_id < 1 || start_id > tablePageData.total){
  1913. alert("请输入正确的追踪起始图片ID,范围为1到" + tablePageData.total);
  1914. return;
  1915. }
  1916. if(end_id < 1 || end_id > tablePageData.total){
  1917. alert("请输入正确的追踪结束图片ID,范围为1到" + tablePageData.total);
  1918. return;
  1919. }
  1920. if(label_id < 1){
  1921. alert("标注框ID为大于等于1的整数。");
  1922. return;
  1923. }
  1924. }
  1925. document.getElementById('predtask_id').disabled=true;
  1926. $.ajax({
  1927. type:"POST",
  1928. url:ip + "/gitea/auto-label-task",
  1929. contentType:'application/json',
  1930. headers: {
  1931. authorization:token,
  1932. },
  1933. dataType:"json",
  1934. async:false,
  1935. data:JSON.stringify({'label_task_id':item_id,
  1936. 'model':predict_model_val,
  1937. 'pic_object_name' : img.width + "," + img.height,
  1938. 'task_type':task_type,
  1939. 'startIndex':start_id,
  1940. 'endIndex':end_id,
  1941. 'taskId':label_task,
  1942. 'label_id':label_id,
  1943. 'label_option':label_option
  1944. }),
  1945. success:function(res){
  1946. console.log('创建数据信息');
  1947. },
  1948. error:function(response) {
  1949. redirect(response);
  1950. }
  1951. });
  1952. setIntervalToDo();
  1953. }
  1954. var timeId;
  1955. var count;
  1956. var progress;
  1957. function setIntervalToDo(){
  1958. count=0;
  1959. timeId = self.setInterval("clock()",1000);//5秒刷新
  1960. console.log("开始刷新。timeId=" + timeId);
  1961. }
  1962. function clock(){
  1963. count++;
  1964. if(count > 600 ){
  1965. console.log("清除定时器。timeId=" + timeId);
  1966. window.clearInterval(timeId);
  1967. timeId = null;
  1968. $("#autoLabel").modal('hide');
  1969. return;
  1970. }
  1971. $.ajax({
  1972. type:"GET",
  1973. url:ip + "/api/query-auto-label-task-progress/",
  1974. headers: {
  1975. authorization:token,
  1976. },
  1977. dataType:"json",
  1978. data:{'taskId': label_task},
  1979. async:false,
  1980. success:function(json){
  1981. progress = json;
  1982. console.log(json);
  1983. },
  1984. error:function(response) {
  1985. progress = null;
  1986. console.log("query progress error");
  1987. redirect(response);
  1988. }
  1989. });
  1990. if(isEmpty(progress)){
  1991. console.log("清除定时器。timeId=" + timeId);
  1992. bar.style.width='100%';
  1993. document.getElementById('text-progress').innerHTML='100%';
  1994. window.clearInterval(timeId);
  1995. timeId = null;
  1996. var current = $('#displayPage1').text();
  1997. $("#autoLabel").modal('hide');
  1998. console.log("开始获取结果。current=" + current);
  1999. if(current >= 1){
  2000. pageReload(current - 1,pageSize,fileindex);
  2001. }
  2002. }else{
  2003. //更新进度
  2004. var iSpeed = progress.progress;
  2005. bar.style.width=iSpeed+'%';
  2006. document.getElementById('text-progress').innerHTML=iSpeed+'%'
  2007. }
  2008. /*
  2009. var current = $('#displayPage1').text();
  2010. console.log("开始刷新。current=" + current);
  2011. if(current >= 1){
  2012. pageReload(current - 1,pageSize,fileindex);
  2013. if(!isEmpty(labeltastresult[fileindex].label_info)){
  2014. window.clearInterval(timeId);
  2015. timeId = null;
  2016. }
  2017. }
  2018. */
  2019. }
  2020. function submit_deletelabel(){
  2021. var start_id = $('#delete_startid').val();
  2022. var end_id = $('#delete_endid').val();
  2023. if(start_id < 1 || start_id > tablePageData.total){
  2024. alert("请输入正确的起始图片ID,范围为1到" + tablePageData.total);
  2025. return;
  2026. }
  2027. if(end_id < 1 || end_id > tablePageData.total){
  2028. alert("请输入正确的结束图片ID,范围为1到" + tablePageData.total);
  2029. return;
  2030. }
  2031. //var one_reid_name = $('#one_reid_name').val();
  2032. $.ajax({
  2033. type:"POST",
  2034. url:ip + "/gitea/label-task-delete-label",
  2035. headers: {
  2036. authorization:token,
  2037. },
  2038. dataType:"json",
  2039. async:false,
  2040. data:{'label_task_id':label_task_info.id,
  2041. 'start_id':start_id,
  2042. 'end_id' : end_id
  2043. //'one_reid_name':one_reid_name
  2044. },
  2045. success:function(res){
  2046. console.log('创建数据信息');
  2047. },
  2048. error:function(response) {
  2049. redirect(response);
  2050. }
  2051. });
  2052. $("#deleteLabel").modal('hide');
  2053. var current = $('#displayPage1').text();
  2054. if(current >= 1){
  2055. pageReload(current - 1,pageSize,fileindex);
  2056. }
  2057. }
  2058. function updatelabel(fileindex){
  2059. var label_list=[]
  2060. for (var i=0;i<rects.length;i++){
  2061. x1y1x2y2=rects[i].getX1Y1X2Y2();
  2062. rects[i].type = '';//regions[i].other.["region_attributes"]["type"];
  2063. var label= {'class_name':rects[i].type, "score":1.0};
  2064. if(!isEmpty(rects[i].other.region_attributes.type)){
  2065. label['class_name'] = rects[i].other.region_attributes.type;
  2066. }
  2067. if(!isEmpty(rects[i].other.region_attributes.id)){
  2068. rects[i].id = rects[i].other.region_attributes.id;
  2069. }
  2070. var xmin = getRealLocationX(x1y1x2y2[0]);
  2071. var ymin = getRealLocationY(x1y1x2y2[1]);
  2072. var xmax = getRealLocationX(x1y1x2y2[2]);
  2073. var ymax = getRealLocationY(x1y1x2y2[3]);
  2074. label['box']=[xmin,ymin, xmax,ymax];
  2075. if(isEmpty(rects[i].id)){
  2076. label['id'] = i+'';
  2077. }else{
  2078. label['id'] = rects[i].id+'';
  2079. }
  2080. label['blurred']=rects[i].blurred;
  2081. label['goodIllumination']=rects[i].goodIllumination;
  2082. label['frontview']=rects[i].frontview;
  2083. label['other']=rects[i].other;
  2084. //console.log(label);
  2085. label_list.push(label);
  2086. }
  2087. for (var i=0;i<masks.length;i++){
  2088. masks[i].type = '';//regions[i].other.["region_attributes"]["type"];
  2089. var label = {'class_name':masks[i].type, "score":1.0};
  2090. if(!isEmpty(masks[i].other.region_attributes.type)){
  2091. label['class_name'] = masks[i].other.region_attributes.type;
  2092. }
  2093. if(!isEmpty(masks[i].other.region_attributes.id)){
  2094. masks[i].id = masks[i].other.region_attributes.id;
  2095. }
  2096. var labelMaskList = [];
  2097. for(var j = 0; j < masks[i].points.length; j++){
  2098. labelMaskList.push(getRealLocationX(masks[i].points[j].x));
  2099. labelMaskList.push(getRealLocationY(masks[i].points[j].y));
  2100. }
  2101. label['mask'] = labelMaskList;
  2102. label['id'] = masks[i].id+'';
  2103. label['blurred']=masks[i].blurred;
  2104. label['goodIllumination']=masks[i].goodIllumination;
  2105. label['frontview']=masks[i].frontview;
  2106. label['other']=masks[i].other;
  2107. //console.log(label);
  2108. label_list.push(label);
  2109. }
  2110. for (var i=0;i<pointShapes.length;i++){
  2111. pointShapes[i].type = '';//regions[i].other.["region_attributes"]["type"];
  2112. var label = {'class_name':pointShapes[i].type, "score":1.0};
  2113. if(!isEmpty(pointShapes[i].other.region_attributes.type)){
  2114. label['class_name'] = pointShapes[i].other.region_attributes.type;
  2115. }
  2116. if(!isEmpty(pointShapes[i].other.region_attributes.id)){
  2117. pointShapes[i].id = pointShapes[i].other.region_attributes.id;
  2118. }
  2119. var pointList = [];
  2120. pointList.push(getRealLocationX(pointShapes[i].x));
  2121. pointList.push(getRealLocationY(pointShapes[i].y));
  2122. pointList.push(2);//0表示这个关键点没有标注(这种情况下x=y=v=0),1表示这个关键点标注了但是不可见(被遮挡了),2 表示这个关键点标注了同时也可见
  2123. label['keypoints'] = pointList;
  2124. label['id'] = pointShapes[i].id+'';
  2125. label['blurred']=pointShapes[i].blurred;
  2126. label['goodIllumination']=pointShapes[i].goodIllumination;
  2127. label['frontview']=pointShapes[i].frontview;
  2128. label['other']=pointShapes[i].other;
  2129. //console.log(label);
  2130. label_list.push(label);
  2131. }
  2132. labelinfo_jsonstr = JSON.stringify(label_list);
  2133. labeltastresult[fileindex].label_info=labelinfo_jsonstr;
  2134. var flag = 0;
  2135. if(isVerified()){
  2136. labeltastresult[fileindex].verify_status=1;
  2137. flag = 100;
  2138. }else{
  2139. if(label_list.length > 0){
  2140. labeltastresult[fileindex].label_status=0;
  2141. }
  2142. else{
  2143. labeltastresult[fileindex].label_status=1;
  2144. }
  2145. }
  2146. $.ajax({
  2147. type:"PATCH",
  2148. url:ip + "/gitea/label-task-item/",
  2149. contentType:'application/json',
  2150. headers: {
  2151. authorization:token,
  2152. },
  2153. dataType:"json",
  2154. async:false,
  2155. data:JSON.stringify({'id':labeltastresult[fileindex].id,
  2156. 'label_task_id':label_task_info.id,
  2157. 'label_info':labelinfo_jsonstr,
  2158. 'label_status': labeltastresult[fileindex].label_status,
  2159. 'verify_status': labeltastresult[fileindex].verify_status,
  2160. 'pic_object_name' : img.width + "," + img.height,
  2161. 'display_order2':flag
  2162. }),
  2163. success:function(json){
  2164. return true;
  2165. },
  2166. error:function(response) {
  2167. redirect(response);
  2168. }
  2169. });
  2170. return false;
  2171. }
  2172. function get_labeltask(){
  2173. console.log('query labeltask info.');
  2174. $.ajax({
  2175. type:"GET",
  2176. url:ip + "/gitea/label-task/"+label_task+"/",
  2177. headers: {
  2178. authorization:token,
  2179. },
  2180. dataType:"json",
  2181. async:false,
  2182. success:function(json){
  2183. label_task_info = json;
  2184. console.log('return labeltask info.' + label_task_info);
  2185. page(0,pageSize);
  2186. },
  2187. error:function(response) {
  2188. redirect(response);
  2189. }
  2190. });
  2191. }
  2192. function update_labeltask(task_label_type_info){
  2193. console.log("label_task_id=" + label_task_info.id);
  2194. console.log("task_label_type_info=" + task_label_type_info);
  2195. $.ajax({
  2196. type:"PATCH",
  2197. url:ip + "/gitea/label-task/",
  2198. headers: {
  2199. authorization:token,
  2200. },
  2201. dataType:"json",
  2202. data:{
  2203. 'label_task_id':label_task_info.id,
  2204. 'task_label_type_info':task_label_type_info,
  2205. },
  2206. async:false,
  2207. success:function(json){
  2208. console.log(json);
  2209. },
  2210. error:function(response) {
  2211. redirect(response);
  2212. }
  2213. });
  2214. }
  2215. function list(current,pageSize,index=0){
  2216. $.ajax({
  2217. type:"GET",
  2218. url:ip + "/gitea/label-task-item-page/",
  2219. headers: {
  2220. authorization:token,
  2221. },
  2222. dataType:"json",
  2223. data:{
  2224. 'label_task':label_task_info.id,
  2225. 'startPage':current,
  2226. 'pageSize':pageSize,
  2227. 'orderType': orderType,
  2228. 'findLast':findLast,
  2229. },
  2230. async:false,
  2231. success:function(json){
  2232. tablePageData = json;
  2233. tableData = json.data;
  2234. labeltastresult = tableData;
  2235. fileindex=index;
  2236. if(lastindex){
  2237. fileindex = pageSize - 1;
  2238. }
  2239. //console.log(json);
  2240. // return json.token;
  2241. },
  2242. error:function(response) {
  2243. redirect(response);
  2244. }
  2245. });
  2246. }
  2247. var pageSize = 20;
  2248. var tableData;
  2249. var tablePageData;
  2250. function pageReload(current,pageSize,fileindex){
  2251. list(current,pageSize,fileindex);
  2252. loadimg();
  2253. showtaskinfo();
  2254. showfilelist();
  2255. //display_list();
  2256. setPage(tablePageData,pageSize);
  2257. }
  2258. function page(current,pageSize){
  2259. list(current,pageSize);
  2260. loadimg();
  2261. showtaskinfo();
  2262. showfilelist();
  2263. //display_list();
  2264. setPage(tablePageData,pageSize);
  2265. }
  2266. function nextPage(){
  2267. hidePopup();
  2268. var current = $('#displayPage1').text();
  2269. console.log("current=" + current);
  2270. findLast = 0;
  2271. page(current,pageSize);
  2272. }
  2273. function prePage(){
  2274. hidePopup();
  2275. var current =$('#displayPage1').text();
  2276. console.log("current=" + current);
  2277. if(current > 1){
  2278. console.log("current=" + (current - 2));
  2279. findLast = 0;
  2280. page(current - 2,pageSize);
  2281. }
  2282. }
  2283. function goPage(){
  2284. hidePopup();
  2285. var goNum = $('#goNum').val();
  2286. findLast = 0;
  2287. var pageTotal = $("#totalNum").text();
  2288. var pageNum = parseInt(pageTotal/pageSize);
  2289. if(pageTotal%pageSize!=0){
  2290. pageNum += 1;
  2291. }else {
  2292. pageNum = pageNum;
  2293. }
  2294. if (goNum<=0){
  2295. alert("请输入大于0的数值");
  2296. }
  2297. else if(goNum<=pageNum){
  2298. page(goNum - 1,pageSize);
  2299. }
  2300. else{
  2301. alert("不能超出总页码!");
  2302. }
  2303. }
  2304. $("#goNum").keydown(function (e) {
  2305. if (e.keyCode == 13) {
  2306. goPage();
  2307. }
  2308. });
  2309. function setPage(pageData,pageSize){
  2310. var startIndex = pageData.current * pageSize;
  2311. if(startIndex < 10){
  2312. $('#startIndex').text(" " + (pageData.current * pageSize + 1));
  2313. }else{
  2314. $('#startIndex').text(pageData.current * pageSize + 1);
  2315. }
  2316. var endIndex = pageData.current * pageSize + pageData.data.length;
  2317. if(endIndex < 10){
  2318. $('#endIndex').text(" " + (pageData.current * pageSize + pageData.data.length));
  2319. }else{
  2320. $('#endIndex').text(pageData.current * pageSize + pageData.data.length);
  2321. }
  2322. $('#totalNum').text(pageData.total);
  2323. $('#displayPage1').text(pageData.current + 1);
  2324. console.log("set prePage status, pageData.current=" + pageData.current);
  2325. if(pageData.current == 0){
  2326. console.log("set prePage disabled.");
  2327. $('#prePage').removeAttr("href");
  2328. $('#prePage').attr('style','color:#000;margin-right:1em;');
  2329. }
  2330. else{
  2331. $('#prePage').attr("href","javascript:prePage()");
  2332. $('#prePage').attr('style','color:#f5f5f6;margin-right:1em;');
  2333. }
  2334. if((pageData.current + 1) * pageSize >= pageData.total){
  2335. console.log("set nextPage disabled.");
  2336. $('#nextPage').removeAttr("href");
  2337. $('#nextPage').attr('style','color:#000;margin-left:1em;')
  2338. }
  2339. else{
  2340. $('#nextPage').attr("href","javascript:nextPage()");
  2341. $('#nextPage').attr('style','color:#f5f5f6;margin-left:1em;');
  2342. }
  2343. var pageTotal = pageData.total;
  2344. var pageNum = parseInt(pageTotal/pageSize);
  2345. if(pageTotal%pageSize!=0){
  2346. pageNum += 1;
  2347. }else {
  2348. pageNum = pageNum;
  2349. }
  2350. $("#totalPageNum").text(pageNum);
  2351. }
  2352. init_index();
  2353. // canvas = document.getElementById("myCanvas");
  2354. // context = canvas.getContext("2d");
  2355. // var maxWidth = document.getElementById("showPic").offsetWidth;
  2356. // var maxHeight = document.getElementById("showPic").offsetHeight-100;
  2357. // canvas.width = maxWidth;//document.getElementById("tool0").offsetWidth;
  2358. // canvas.height = maxHeight;//document.getElementById("tool0").offsetWidth/1280*720;
  2359. // show_region = document.getElementById("show_region");
  2360. // show_region.width =document.getElementById("tool0").offsetWidth;
  2361. // show_region.height = document.getElementById("tool0").offsetWidth/1280*720;
  2362. function init_index() {
  2363. canvas = document.getElementById("myCanvas");
  2364. context = canvas.getContext("2d");
  2365. maxWidth = document.getElementById("showPic").offsetWidth;
  2366. maxHeight = document.getElementById("showPic").offsetHeight-100;
  2367. canvas.width = maxWidth;
  2368. canvas.height = maxHeight;
  2369. canvas.onmousedown = canvasClick;
  2370. canvas.onmouseup = stopDragging;
  2371. canvas.onmouseout = stopDragging;
  2372. canvas.onmousemove =dragRect;
  2373. var token = getSessionStorageMessage("token");
  2374. console.log("page load token=" + token);
  2375. if(!isEmpty(token)){
  2376. console.log("this is not null.token =" + token);
  2377. doLoad();
  2378. }
  2379. };
  2380. function doLoad(){
  2381. token = getSessionStorageMessage("token");
  2382. userType = getSessionStorageMessage("userType");
  2383. if(typeof token == "undefined" || token == null || token == ""){
  2384. console.log("token=" + token);
  2385. console.log("onload tasks/detect/index.html");
  2386. window.location.href = "../../login.html";
  2387. }
  2388. label_task = getSessionStorageMessage("label_task");
  2389. label_task_status = getSessionStorageMessage("label_task_status"); //1表示审核
  2390. get_labeltask();
  2391. drawRect();
  2392. _via_init();
  2393. //加载保存好的属性结构,如果不存在,加载默认的类别信息
  2394. if(!isEmpty(label_task_info.task_label_type_info)){
  2395. label_attributes = JSON.parse(label_task_info.task_label_type_info);
  2396. }
  2397. if (isEmpty(label_attributes)){
  2398. get_init_atrribute();
  2399. }
  2400. else{
  2401. if (Object.keys(label_attributes).length == 0){
  2402. get_init_atrribute();
  2403. }
  2404. else{
  2405. _via_attributes["region"] = label_attributes;
  2406. }
  2407. }
  2408. }
  2409. function get_init_atrribute(){
  2410. _via_attributes = {'region':{}};
  2411. var atti = "id"; // 属性名
  2412. _via_attributes['region'][atti] = {};
  2413. _via_attributes['region'][atti]["type"] = "text";
  2414. _via_attributes['region'][atti]["description"] = "";
  2415. _via_attributes['region'][atti]["default_value"] = "";
  2416. atti = "type"; // 属性名
  2417. _via_attributes['region'][atti] = {};
  2418. _via_attributes['region'][atti]["type"] = "dropdown";
  2419. _via_attributes['region'][atti]["description"] = "";
  2420. _via_attributes['region'][atti]["options"] = {};
  2421. _via_attributes['region'][atti]["options"]["car"] = "car";
  2422. _via_attributes['region'][atti]["options"]["person"] = "person";
  2423. _via_attributes['region'][atti]["options"]["non-motor"] = "non-motor";
  2424. _via_attributes['region'][atti]["default_options"] = {};
  2425. }
  2426. function model_sele_Change(event){
  2427. var modelid = $('#predict_model option:selected').val();
  2428. console.log("predict_model=" + modelid);
  2429. if(modelid == 12 || modelid == 16 || modelid == 20 || modelid == 21){
  2430. document.getElementById("tracking_startid_div").style.display="block";
  2431. document.getElementById("tracking_endid_div").style.display="block";
  2432. document.getElementById("labelOption_div").style.display="block";
  2433. if(modelid == 12 || modelid == 16){
  2434. document.getElementById("label_id_div").style.display="block";
  2435. }else{
  2436. document.getElementById("label_id_div").style.display="none";
  2437. }
  2438. if(modelid == 21){
  2439. document.getElementById("labelOption").innerHTML="<option value=\"10\" selected=\"\">person</option> <option value=\"11\">car</option>";
  2440. }else if(modelid == 20){
  2441. document.getElementById("labelOption").innerHTML="<option value=\"10\" selected=\"\">person</option>";
  2442. }else{
  2443. document.getElementById("labelOption").innerHTML="<option value=\"0\" selected=\"\">合并已有的标注信息</option> <option value=\"1\">删除已有的标注信息</option>";
  2444. }
  2445. }else{
  2446. document.getElementById("tracking_startid_div").style.display="none";
  2447. document.getElementById("tracking_endid_div").style.display="none";
  2448. document.getElementById("label_id_div").style.display="none";
  2449. document.getElementById("labelOption_div").style.display="none";
  2450. if(modelid == 5 || modelid == 6 || modelid == 7 ){
  2451. //document.getElementById("labelOption").innerHTML="<option value=\"2\" selected=\"\">请选择</option> <option value=\"3\">识别车的类型与颜色</option>";
  2452. }
  2453. }
  2454. }
  2455. function export_attribute(){
  2456. var url = ip + "/api/task-export-label-property/";
  2457. var $iframe = $('<iframe />');
  2458. var $form = $('<form method="get" target="_self"/>');
  2459. $form.attr('action', url); //设置get的url地址
  2460. $form.append('<input type="hidden" name="task_id" value="' + label_task + '" />');
  2461. $form.append('<input type="hidden" name="type" value="labeltask" />');
  2462. $iframe.append($form);
  2463. $(document.body).append($iframe);
  2464. $form[0].submit();//提交表单
  2465. $iframe.remove();//移除框架
  2466. }
  2467. function import_attribute(){
  2468. $('#datasetModal').modal('show');
  2469. }
  2470. function submit_import_property(){
  2471. var jsonContent = $("#jsoninput").val();
  2472. if(!isJSON(jsonContent)){
  2473. alert("输入格式非法。");
  2474. return;
  2475. }
  2476. $.ajax({
  2477. type:"POST",
  2478. url:ip + "/api/task-import-label-property/",
  2479. headers: {
  2480. authorization:token,
  2481. },
  2482. dataType:"json",
  2483. data:{
  2484. 'jsonContent':jsonContent,
  2485. 'taskType':"labeltask",
  2486. 'taskId':label_task
  2487. },
  2488. async:false,
  2489. success:function(json){
  2490. console.log(json);
  2491. },
  2492. error:function(response) {
  2493. redirect(response);
  2494. }
  2495. });
  2496. $('#datasetModal').modal('hide');
  2497. close_attribute();
  2498. }
  2499. function isJSON(str) {
  2500. if (typeof str == 'string') {
  2501. try {
  2502. var obj=JSON.parse(str);
  2503. if(typeof obj == 'object' && obj ){
  2504. return true;
  2505. }else{
  2506. return false;
  2507. }
  2508. } catch(e) {
  2509. console.log('error:'+str+'!!!'+e);
  2510. return false;
  2511. }
  2512. }
  2513. console.log('It is not a string!');
  2514. return false;
  2515. }
  2516. img.onload = function(){
  2517. loadFinished = false;
  2518. // 初始设置画布大小,最大值宽和高
  2519. canvas.width = maxWidth;//document.getElementById("tool0").offsetWidth;
  2520. canvas.height = maxHeight;//document.getElementById("tool0").offsetWidth/1280*720;
  2521. //调整画布大小
  2522. if ((img.width/img.height)<(canvas.width/canvas.height)){
  2523. canvas.width=canvas.height * img.width / img.height;
  2524. }
  2525. else{
  2526. canvas.height=canvas.width * img.height / img.width;
  2527. }
  2528. maxIdNum=0;
  2529. parse_labelinfo(labeltastresult[fileindex].label_info);
  2530. drawRect();
  2531. $('#filepanel').slimScroll({
  2532. alwaysVisible: true, //是否 始终显示组件(未更改库文件时,鼠标移开滚动条消失)
  2533. });
  2534. canvas.onmousewheel = canvas.onwheel = function (event) { //滚轮放大缩小
  2535. console.log("primivate x,y=" + event.clientX + "," + event.clientY);//鼠标在屏幕上的位置
  2536. event.wheelDelta = event.wheelDelta ? event.wheelDelta : (event.deltalY * (-40)); //获取当前鼠标的滚动情况
  2537. if (event.wheelDelta > 0) {// 放大
  2538. imgScale +=0.1;
  2539. console.log("imgScale=" + imgScale);
  2540. } else {// 缩小
  2541. imgScale -=0.1;
  2542. if(imgScale< 1) {//最小缩放1
  2543. imgScale = 1;
  2544. }
  2545. console.log("imgScale=" + imgScale);
  2546. }
  2547. drawRect(); //重新绘制图片
  2548. };
  2549. loadFinished=true;
  2550. };
  2551. document.onkeydown = function(e){
  2552. switch(e.keyCode){
  2553. case 37:
  2554. case 38:
  2555. case 39:
  2556. case 40:
  2557. e.preventDefault();
  2558. }
  2559. }
  2560. document.onkeyup=function(e){
  2561. console.log(e.keyCode)
  2562. console.log(window.event);
  2563. e=e||window.event;
  2564. e.preventDefault();
  2565. obj = e.srcElement||e.target;
  2566. if( obj != null && obj !=undefined ){
  2567. if(obj.type == "textarea" || obj.type=='text'){
  2568. //console.log("obj.type:"+obj.type);
  2569. return ;
  2570. }
  2571. }
  2572. switch(e.keyCode){
  2573. case 87: //W
  2574. // boxcls = classes;
  2575. createRectLabel();
  2576. break;
  2577. case 68:
  2578. deleterect();
  2579. break;
  2580. case 27:
  2581. cancel();
  2582. break;
  2583. case 83:
  2584. save();
  2585. break;
  2586. case 81:
  2587. last();
  2588. break;
  2589. case 69:
  2590. next();
  2591. break;
  2592. case 90://u
  2593. undo();
  2594. break;
  2595. case 67://c
  2596. copyOneBox();
  2597. break;
  2598. case 86://v
  2599. paste();
  2600. break;
  2601. case 37:
  2602. moveLeftSinglePx();
  2603. break;
  2604. case 38:
  2605. moveUpSinglePx();
  2606. break;
  2607. case 39:
  2608. moveRightSinglePx();
  2609. break;
  2610. case 40:
  2611. moveDownSinglePx();
  2612. break;
  2613. };
  2614. }