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 88 kB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957
  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 picIndex = picturePath.indexOf("/",70);
  629. if(picIndex != -1){
  630. float_text_name = picturePath.substring(picIndex + 1);
  631. float_text_name = float_text_name.substring(float_text_name.indexOf('/')+1);
  632. }else{
  633. float_text_name = picturePath.substring(picturePath.lastIndexOf("/") + 1)
  634. }
  635. var html = float_text_name + "&nbsp;&nbsp;&nbsp;&nbsp;"+ "(" + (tablePageData.current * pageSize + fileindex + 1) + "/" + tablePageData.total + ")"
  636. document.getElementById("float_text").innerHTML = html;
  637. }
  638. function save(){
  639. hidePopup();
  640. var re = updatelabel(fileindex);
  641. if (re=true){
  642. //window.alert("保存成功!");
  643. }
  644. else{window.alert("保存失败!");}
  645. showfilelist();
  646. }
  647. function clearCache(){
  648. rects = [];
  649. masks = [];
  650. pointShapes = [];
  651. }
  652. function next(){
  653. currentImage = false;
  654. hidePopup();
  655. if(fileindex<labeltastresult.length-1) {
  656. if(loadFinished==true){
  657. updatelabel(fileindex);
  658. }
  659. clearCache();
  660. fileindex=fileindex+1;
  661. loadimg();
  662. showfilelist();
  663. }else{
  664. if((tablePageData.current + 1) * pageSize < tablePageData.total){
  665. if (loadFinished==true){
  666. updatelabel(fileindex);
  667. }
  668. clearCache();
  669. nextPage();
  670. }
  671. }
  672. loadFinished=false;
  673. }
  674. function last(){
  675. currentImage = false;
  676. hidePopup();
  677. if(fileindex>0){
  678. if(loadFinished==true){
  679. loadFinished=false;
  680. updatelabel(fileindex);
  681. }
  682. clearCache();
  683. fileindex=fileindex-1;
  684. loadimg();
  685. showfilelist();
  686. }else{
  687. var current = $('#displayPage1').text();
  688. if(current > 1){
  689. lastindex = true;
  690. if(loadFinished==true){
  691. loadFinished=false;
  692. updatelabel(fileindex);
  693. }
  694. clearCache();
  695. prePage();
  696. lastindex = false;
  697. }
  698. }
  699. }
  700. function clickfilelist(index){
  701. hidePopup();
  702. clearCache();
  703. fileindex = index;
  704. loadimg();
  705. showfilelist();
  706. currentImage = false;
  707. }
  708. //画布操作、
  709. //
  710. //
  711. function onpoint(x,y,pt){
  712. var biasx = Math.abs(x - pt.x);
  713. var biasy = Math.abs(y - pt.y);
  714. if ((biasx<=3) && (biasy<=3)){
  715. return true;
  716. }
  717. else{
  718. return false;
  719. }
  720. }
  721. function onrect(x,y,recta){
  722. rectxywh = recta.getXYWH();
  723. widthstart=rectxywh[0];
  724. widthend=rectxywh[0]+rectxywh[2];
  725. heightstart=rectxywh[1];
  726. heightend=rectxywh[1]+rectxywh[3];
  727. if ((x>=widthstart&&x<(widthend))&&(y>=heightstart)&&(y<(heightend))){
  728. return true;
  729. }
  730. else{
  731. return false;
  732. }
  733. }
  734. function clearboard(){
  735. context.clearRect(0, 0, canvas.width, canvas.height);
  736. }
  737. function fillMask(mask){
  738. context.beginPath();
  739. context.moveTo(bigLocX(mask.points[0].x), bigLocY(mask.points[0].y));
  740. for (var i=1; i<mask.points.length; i++){
  741. context.lineTo(bigLocX(mask.points[i].x), bigLocY(mask.points[i].y));
  742. }
  743. context.closePath();
  744. context.fill();
  745. }
  746. //判断一个点是否在多边形中。
  747. //核心是从这个点出发垂直线或水平线,与多边形相交的次数一定是奇数
  748. function onmask_new(x,y, mask,vs) {
  749. var vs = mask.points;
  750. var inside = false;
  751. for (var i = 0, j = vs.length - 1; i < vs.length; j = i++) {
  752. var xi = vs[i].x, yi = vs[i].y;
  753. var xj = vs[j].x, yj = vs[j].y;
  754. var intersect = ((yi > y) != (yj > y))
  755. && (x < (xj - xi) * (y - yi) / (yj - yi) + xi);
  756. if (intersect) inside = !inside;
  757. }
  758. return inside;
  759. };
  760. function drawRect(x=null,y=null,resize=0) {
  761. //document.getElementById("boxlabels").innerHTML=boxlabelshtml();
  762. //document.getElementById("labelcounttable").innerHTML=boxlabelcounthtml();
  763. //清除画布,准备绘制
  764. context.clearRect(0, 0, canvas.width, canvas.height);
  765. var imgWidth = canvas.width;
  766. var imgHeight = canvas.height
  767. if(imgScale > 1){//当没有放大时,就用画布的大小
  768. imgWidth = canvas.width * imgScale;
  769. imgHeight = canvas.height * imgScale;
  770. }
  771. //console.log("startx=" + startx + " starty=" + starty + " img.width=" + img.width + " imgWidth=" + imgWidth + " imgScale=" + imgScale + " img.width / (canvas.width * imgScale)=" + (img.width / (canvas.width * imgScale)));
  772. context.drawImage(
  773. img, //规定要使用的图像、画布或视频。
  774. startx, starty, //开始剪切的 x 坐标位置。
  775. img.width, img.height, //被剪切图像的高度。
  776. //imgWidth, imgHeight,
  777. 0, 0,//在画布上放置图像的 x 、y坐标位置。
  778. imgWidth, imgHeight //要使用的图像的宽度、高度
  779. //canvas.width,canvas.height
  780. );
  781. //context.drawImage(img, 0, 0, imgWidth, imgHeight, 0, 0, canvas.width, canvas.height);
  782. //context.drawImage(img,0,0,canvas.width,canvas.height);
  783. //遍历画所有矩形框
  784. drawRectShape();
  785. //创建Rect时,显示横竖两条黑线
  786. if (tocreaterect && (x!=-1)){
  787. //row
  788. context.strokeStyle="black"
  789. context.beginPath();
  790. context.moveTo(0,y);
  791. context.lineTo(canvas.width,y);
  792. context.moveTo(x,0);
  793. context.lineTo(x,canvas.height);
  794. context.stroke();
  795. context.closePath();
  796. }
  797. //遍历画所有Mask矩形框
  798. drawMaskShape(x,y);
  799. //遍历画所有的圆点
  800. drawPointShape();
  801. }
  802. function drawPointShape(){
  803. for(var i = 0; i < pointShapes.length; i++){
  804. context.strokeStyle="yellow";
  805. selectColor(pointShapes,i);
  806. context.beginPath();//标志开始一个路径
  807. context.arc(bigLocX(pointShapes[i].x),bigLocY(pointShapes[i].y),5,0,2*Math.PI);//在canvas中绘制圆形
  808. if(pointShapes[i].isSelected){
  809. console.log("choose a point.");
  810. context.fillStyle = "rgba(97, 216, 162, 0.5)";
  811. context.fill();
  812. }
  813. context.stroke()
  814. }
  815. }
  816. function bigLocX(x){
  817. var tmp = img.width / (canvas.width * imgScale);
  818. return x * imgScale - startx/tmp ;
  819. }
  820. function bigLocY(y){
  821. var tmp = img.height / (canvas.height * imgScale);
  822. return y * imgScale - starty /tmp;
  823. }
  824. function smallLocX(x){
  825. var tmp = img.width /canvas.width;
  826. return x / imgScale + startx/tmp;
  827. }
  828. function smallLocY(y){
  829. var tmp = img.height /canvas.height;
  830. return y / imgScale + starty / tmp;
  831. }
  832. //画所有矩形框
  833. function drawRectShape(){
  834. var drawLineWidth = 1;
  835. for(var i=0; i<rects.length; i++) {
  836. var rect = rects[i];
  837. rectxywh = rect.getXYWH();
  838. x1y1x2y2 = rect.getX1Y1X2Y2();
  839. // 绘制矩形
  840. if (rect.isSelected) {
  841. context.fillStyle = "rgba(97, 216, 162, 0.7)";
  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 if(rect.mouseonrect || rect.mouseonpoint){//鼠标移到矩形框中或者在矩形点上
  848. context.fillStyle = "rgba(97, 216, 162, 0.2)";
  849. //context.fillStyle = "rgba(10, 114, 6, 0.5)";
  850. //context.fillRect(bigLocX(rectxywh[0]),bigLocY(rectxywh[1]),bigLocX(rectxywh[2]),bigLocY(rectxywh[3]));
  851. context.fillRect(bigLocX(x1y1x2y2[0]),bigLocY(x1y1x2y2[1]),bigLocX(x1y1x2y2[2]) - bigLocX(x1y1x2y2[0]),bigLocY(x1y1x2y2[3]) - bigLocY(x1y1x2y2[1]));
  852. context.lineWidth = drawLineWidth;
  853. }
  854. else{
  855. context.lineWidth = drawLineWidth;
  856. }
  857. // if(rect.type == "person"){
  858. // context.strokeStyle = color_person[ i % 4];
  859. // }else{
  860. context.strokeStyle=color_dict["rect"]; //初始颜色
  861. // }
  862. selectColor(rects,i);
  863. setVerifyLineWidth(rect);
  864. //context.strokeRect(bigLocX(rectxywh[0]),bigLocY(rectxywh[1]),bigLocX(rectxywh[2]),bigLocY(rectxywh[3]),rect.color);
  865. context.strokeRect(bigLocX(x1y1x2y2[0]),bigLocY(x1y1x2y2[1]),bigLocX(x1y1x2y2[2]) - bigLocX(x1y1x2y2[0]),bigLocY(x1y1x2y2[3]) - bigLocY(x1y1x2y2[1]),rect.color);
  866. setVerifyText(rect,bigLocX(x1y1x2y2[0]),bigLocY(x1y1x2y2[1]));
  867. for(var j=0; j<4; j++){
  868. var p = rect.points[j]
  869. // context.fillStyle = "green";
  870. // context.fillRect(p.x-3,p.y-3,6,6);
  871. if (rect.mouseonpoint){
  872. context.fillStyle = color_dict["pointselected"];
  873. context.fillRect(bigLocX(p.x)-5,bigLocY(p.y)-5,10,10);
  874. }
  875. else{
  876. context.fillStyle = color_dict["point"];
  877. context.fillRect(bigLocX(p.x)-3,bigLocY(p.y)-3,6,6);
  878. }
  879. }
  880. }
  881. }
  882. function setVerifyText(rect,x,y){
  883. if(!isEmpty(rect.other.region_attributes.verify)){
  884. if(rect.other.region_attributes.verify != 0){
  885. context.font = "15px Georgia";
  886. context.fillStyle= context.strokeStyle;
  887. context.fillText(verifyMap[rect.other.region_attributes.verify], x,y-5);
  888. }
  889. }
  890. }
  891. function setVerifyLineWidth(rect){
  892. if(!isEmpty(rect.other.region_attributes.verify)){
  893. if(rect.other.region_attributes.verify != 0){
  894. context.lineWidth = 3;
  895. context.strokeStyle = "#DC143C";
  896. }
  897. }
  898. }
  899. function selectColor(regions,i){
  900. if(!isEmpty(_via_attributes['region']['type'])){
  901. var dict = _via_attributes['region']['type']["options"];
  902. var color_num=0;
  903. for (var key in dict){
  904. if (key==regions[i].other.region_attributes.type){
  905. context.strokeStyle=color_all[String(color_num)];
  906. break;
  907. }
  908. color_num++;
  909. }
  910. }
  911. }
  912. function drawMaskShape(x,y){
  913. for (var i=0; i<masks.length; i++){
  914. context.strokeStyle="purple"
  915. var mask =masks[i];
  916. if (mask.isSelected){
  917. context.lineWidth = 3;
  918. }
  919. else{
  920. context.lineWidth = 2;
  921. }
  922. selectColor(masks,i);
  923. for (var j=1; j<mask.points.length; j++){
  924. context.beginPath();
  925. context.moveTo(bigLocX(mask.points[j-1].x), bigLocY(mask.points[j-1].y));
  926. context.lineTo(bigLocX(mask.points[j].x),bigLocY(mask.points[j].y));
  927. context.stroke();
  928. // context.closePath();
  929. }
  930. if(mask.finish){
  931. context.moveTo(bigLocX(mask.points[mask.points.length-1].x), bigLocY(mask.points[mask.points.length-1].y));
  932. context.lineTo(bigLocX(mask.points[0].x), bigLocY(mask.points[0].y));
  933. context.stroke();
  934. context.closePath();
  935. // 绘制Mask
  936. if (mask.isSelected) {
  937. context.fillStyle = "rgba(97, 216, 162, 0.5)";
  938. fillMask(mask);
  939. }
  940. else if(mask.mouseonmask || mask.mouseonpoint){
  941. context.fillStyle = "rgba(97, 216, 162, 0.2)";
  942. fillMask(mask);
  943. }
  944. }
  945. else{
  946. if(x&&y){
  947. context.beginPath();
  948. context.moveTo(bigLocX(mask.points[mask.points.length-1].x),bigLocY(mask.points[mask.points.length-1].y));
  949. context.lineTo(x,y);
  950. context.stroke();
  951. // context.closePath();
  952. }
  953. }
  954. for (var j=0; j<mask.points.length; j++){
  955. var p = mask.points[j]
  956. if (onpoint(smallLocX(x),smallLocY(y),p)){
  957. context.fillStyle = color_dict["pointselected"];
  958. context.fillRect(bigLocX(p.x)-5,bigLocY(p.y)-5,10,10);
  959. }
  960. else{
  961. context.fillStyle = color_dict["point"];
  962. context.fillRect(bigLocX(p.x)-3,bigLocY(p.y)-3,6,6);
  963. }
  964. }
  965. }
  966. }
  967. function resetSelectShapeEmpty(){
  968. if (Selectedmask != null){
  969. console.log("set select mask is null.");
  970. if (SelectedmaskpointId != null){
  971. Selectedmask.points[SelectedmaskpointId].isSelected = false;
  972. SelectedmaskpointId = null;
  973. }
  974. Selectedmask.isSelected = false;
  975. Selectedmask = null;
  976. }
  977. if (SelectedRect != null){
  978. console.log("set select rect is null.");
  979. if (SelectedpointId != null){
  980. SelectedRect.points[SelectedpointId].isSelected = false;
  981. SelectedpointId= null;
  982. }
  983. SelectedRect.isSelected = false;
  984. SelectedRect = null;
  985. }
  986. if(SelectedPointShape != null){
  987. SelectedPointShape = null;
  988. }
  989. }
  990. function clickPointInMask(clickX,clickY){
  991. //查看点击的点是否是Mask的标注点,如果是,则着重显示该点。
  992. for(var i=masks.length-1; i>=0; i--) {
  993. var mask = masks[i];
  994. var maskpoints = mask.points
  995. for (var j=0;j<maskpoints.length;j++){
  996. var pt = maskpoints[j];
  997. if (onpoint(smallLocX(clickX),smallLocY(clickY),pt)){
  998. mask.isSelected=true;
  999. Selectedmask = mask;
  1000. stretch_mask = true;
  1001. SelectedmaskpointId=j;
  1002. //更新显示
  1003. drawRect(clickX,clickY);
  1004. //停止搜索
  1005. return true;
  1006. }
  1007. }
  1008. }
  1009. //检查点击的点是否在某个Mask的范围内,如果是,则该Mask的范围内背景色需要修改,显示该Mask的标注信息
  1010. for(var i=masks.length-1; i>=0; i--) {
  1011. var mask = masks[i];
  1012. if (onmask_new(smallLocX(clickX),smallLocY(clickY),mask)){
  1013. Selectedmask = mask;
  1014. console.log("at mask.clickX=" + clickX + " clicky=" + clickY);
  1015. mask.isSelected=true;
  1016. Selectedmask = mask;
  1017. // 允许被拉伸
  1018. stretch_mask =true;
  1019. //允许拖动
  1020. isDragging = true;
  1021. old_click_x1=clickX;
  1022. old_click_y1=clickY;
  1023. //更新显示
  1024. drawRect();
  1025. //弹出标注信息框
  1026. var bound = mask.getBound();
  1027. var new_region_id =i;
  1028. regions = masks;
  1029. select_only_region(new_region_id);
  1030. showPopup(bigLocY(bound[3])+5, bigLocX(bound[2])+5,i,"mask");
  1031. // showPopup(bigLocY(bound[3])+145, bigLocX(bound[2]) + 235,i,"mask");
  1032. document.getElementById("boxlabels").innerHTML=boxlabelshtml();
  1033. document.getElementById("labelcounttable").innerHTML=boxlabelcounthtml();
  1034. //停止搜索
  1035. return true;
  1036. }else{
  1037. //console.log("not at mask.clickX=" + clickX + " clicky=" + clickY);
  1038. }
  1039. }
  1040. return false;
  1041. }
  1042. function clickPointInRect(clickX,clickY){
  1043. // //查看点击的点是否是Rect的标注点,如果是,则着重显示该点。
  1044. for(var i=rects.length-1; i>=0; i--) {
  1045. var rect = rects[i];
  1046. var rectpoints = rect.points
  1047. for (var j=0;j<rectpoints.length;j++){
  1048. var pt = rectpoints[j];
  1049. //console.log("clickX,clickY=" + clickX + "," + clickY + " smallLocX,smallLocY=" + smallLocX(clickX) + "," +smallLocY(clickY) + " pt.x,pt.y=" + pt.x + "," + pt.y);
  1050. if (onpoint(smallLocX(clickX),smallLocY(clickY),pt)){
  1051. pt.isSelected=true;
  1052. rect.isSelected=true;
  1053. SelectedRect = rect;
  1054. SelectedpointId = j;
  1055. stretch = true;//允许拉伸
  1056. console.log("choose rect 3333:");
  1057. //更新显示
  1058. drawRect();
  1059. //停止搜索
  1060. return true;
  1061. }
  1062. }
  1063. }
  1064. for(var i=rects.length-1; i>=0; i--) {
  1065. var rect = rects[i];
  1066. if (onrect(smallLocX(clickX),smallLocY(clickY),rect)){
  1067. SelectedRect = rect;
  1068. old_click_x1=clickX;
  1069. old_click_y1=clickY;
  1070. //选择新圆圈
  1071. rect.isSelected = true;
  1072. //允许拖拽
  1073. isDragging = true;
  1074. //更新显示
  1075. drawRect();
  1076. xy = rect.getX1Y1X2Y2();
  1077. 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);
  1078. select_only_region(i);
  1079. showPopup(bigLocY(xy[1])+5, bigLocX(xy[2])+5 , i,"rect");
  1080. // showPopup(bigLocY(xy[3])+145, bigLocX(xy[2]) + 235,i,"rect");
  1081. document.getElementById("boxlabels").innerHTML=boxlabelshtml();
  1082. document.getElementById("labelcounttable").innerHTML=boxlabelcounthtml();
  1083. //停止搜索
  1084. return true;
  1085. }
  1086. }
  1087. return false;
  1088. }
  1089. function clickPointInPointShape(clickX,clickY){
  1090. var t = -1;
  1091. for(var i = 0; i < pointShapes.length; i++){
  1092. if (onpoint(smallLocX(clickX),smallLocY(clickY),pointShapes[i])){
  1093. console.log("clickX=," + clickX + "clickY=," + clickY + " pointShapes[i].x=" + + pointShapes[i].x + "pointShapes[i].y=" + pointShapes[i].y);
  1094. pointShapes[i].isSelected=true;
  1095. SelectedPointShape = pointShapes[i];
  1096. t = i;
  1097. }else{
  1098. pointShapes[i].isSelected=false;
  1099. }
  1100. }
  1101. if( t >= 0){
  1102. drawRect();
  1103. select_only_region(t);
  1104. showPopup(bigLocY(SelectedPointShape.y) +5, bigLocX(SelectedPointShape.x) +5,t,"pointshape");
  1105. // showPopup(bigLocY(SelectedPointShape.y) + 165, bigLocX(SelectedPointShape.x) + 250,t,"pointshape");
  1106. //showPopup(bigLocY(SelectedPointShape.y) + 165, bigLocX(SelectedPointShape.x) + 250,t,"pointshape");
  1107. document.getElementById("boxlabels").innerHTML=boxlabelshtml();
  1108. document.getElementById("labelcounttable").innerHTML=boxlabelcounthtml();
  1109. return true;
  1110. }
  1111. return false;
  1112. }
  1113. //交互
  1114. //画布内鼠标响应操作
  1115. function canvasClick(e) {
  1116. // 取得画布上被单击的点
  1117. var clickX = e.pageX - getElementLeft(canvas);
  1118. var clickY = e.pageY - getElementTop(canvas);
  1119. var smallClickX = smallLocX(clickX);
  1120. var smallClickY = smallLocY(clickY);
  1121. if (tocreaterect){
  1122. var rect=new rectar(smallClickX,smallClickY,smallClickX,smallClickY,boxcls);
  1123. rects.push(rect);
  1124. console.log("draw rect...10");
  1125. showpopVar = true;
  1126. tocreaterect=false;
  1127. hidePopup();
  1128. undoShape = rect;
  1129. }
  1130. if (tocreatemask){
  1131. showpopVar = true;
  1132. hidePopup();
  1133. if (creatingmask == null){
  1134. var mask=new maskar(smallClickX,smallClickY,boxcls);
  1135. masks.push(mask);
  1136. Selectedmask = mask;
  1137. creatingmask = mask;
  1138. }
  1139. else{
  1140. if (onpoint(smallClickX,smallClickY,creatingmask.points[0])){
  1141. Selectedmask.finish=true;
  1142. creatingmask=null;
  1143. tocreatemask=false;
  1144. drawRect();
  1145. var new_region_id =masks.length-1;
  1146. var bound = masks[new_region_id].getBound();
  1147. regions = masks;
  1148. set_region_annotations_to_default_value( new_region_id );
  1149. select_only_region(new_region_id);
  1150. showPopup(bigLocY(bound[3])+5, bigLocX(bound[2])+5,new_region_id,"mask");
  1151. // showPopup(bigLocY(bound[3])+145, bigLocX(bound[2]) + 235,i,"mask");
  1152. document.getElementById("boxlabels").innerHTML=boxlabelshtml();
  1153. document.getElementById("labelcounttable").innerHTML=boxlabelcounthtml();
  1154. undoShape = masks[new_region_id];
  1155. resetSelectShapeEmpty();
  1156. return;
  1157. }
  1158. creatingmask.points.push(new point(smallClickX,smallClickY))
  1159. }
  1160. }
  1161. if(toCreatePoint){
  1162. console.log("point x,y=" + clickX + "," + clickY);
  1163. var pointObj = new pointShape(smallClickX,smallClickY,boxcls);
  1164. pointShapes.push(pointObj);
  1165. var len_points = pointShapes.length;
  1166. var new_region_id =len_points-1;
  1167. regions = pointShapes;
  1168. set_region_annotations_to_default_value(new_region_id);
  1169. toCreatePoint = false;
  1170. undoShape = pointShapes[new_region_id];
  1171. }
  1172. //将选择信息设置为空,在下面重新查找设置
  1173. resetSelectShapeEmpty();
  1174. if(clickPointInPointShape(clickX,clickY)){
  1175. return;
  1176. }
  1177. //如果点在Mask内,已经画完了,则返回。
  1178. if(clickPointInMask(clickX,clickY)){
  1179. return;
  1180. }
  1181. //如果点在Rect内,已经画完了,则返回。
  1182. if(clickPointInRect(clickX,clickY)){
  1183. return;
  1184. }
  1185. //如果点不在标注区域内
  1186. drawRect(clickX,clickY);
  1187. hidePopup();
  1188. dragging = true;
  1189. old_click_x1 = clickX;
  1190. old_click_y1 = clickY;
  1191. }
  1192. function dragRect(e) {
  1193. // 取得鼠标位置
  1194. var x = e.pageX - getElementLeft(canvas);
  1195. var y = e.pageY - getElementTop(canvas);
  1196. var smallX = smallLocX(x);
  1197. var smallY = smallLocY(y);
  1198. if (tocreaterect || tocreatemask){
  1199. drawRect(x,y);
  1200. }
  1201. //悬停变色
  1202. var found=false;
  1203. for(var i=rects.length-1; i>=0; i--) {
  1204. var rect = rects[i];
  1205. var rectpoints = rect.points
  1206. for (var j=0;j<rectpoints.length;j++){
  1207. var pt = rectpoints[j];
  1208. if (onpoint(smallX,smallY,pt)){
  1209. rect.mouseonpoint=true;
  1210. mouseonpoint_rect = rect;
  1211. //更新显示
  1212. drawRect(x,y);
  1213. //停止搜索
  1214. found=true;
  1215. break;
  1216. }
  1217. }
  1218. if (found){
  1219. break;
  1220. }
  1221. }
  1222. for(var i=masks.length-1; i>=0; i--) {
  1223. var mask = masks[i];
  1224. var maskpoints = mask.points
  1225. for (var j=0;j<maskpoints.length;j++){
  1226. var pt = maskpoints[j];
  1227. if (onpoint(smallX,smallY,pt)){
  1228. mask.mouseonpoint=true;
  1229. mouseonpoint_mask = mask;
  1230. //更新显示
  1231. drawRect(x,y);
  1232. //停止搜索
  1233. found=true;
  1234. break;
  1235. }
  1236. }
  1237. if (found){
  1238. break;
  1239. }
  1240. }
  1241. if ((!found)&& (mouseonpoint_mask!=null)&&(!stretch)) {
  1242. mouseonpoint_mask.mouseonpoint=false;
  1243. mouseonpoint_mask=null;
  1244. drawRect(x,y);
  1245. }
  1246. if ((!found)&& (mouseonpoint_rect!=null)&&(!stretch)) {
  1247. mouseonpoint_rect.mouseonpoint=false;
  1248. mouseonpoint_rect=null;
  1249. drawRect(x,y);
  1250. }
  1251. if (!found){//不在点上
  1252. for(var i=rects.length-1; i>=0; i--) {
  1253. var rect = rects[i];
  1254. if (onrect(smallX,smallY,rect)){
  1255. if (mouseonrect_rect) {mouseonrect_rect.mouseonrect=false;}
  1256. rect.mouseonrect=true;
  1257. mouseonrect_rect = rect;
  1258. //更新显示
  1259. drawRect(x,y);
  1260. //停止搜索
  1261. found=true;
  1262. break;
  1263. }
  1264. }
  1265. for(var i=masks.length-1; i>=0; i--) {
  1266. var mask = masks[i];
  1267. var maskpoints = mask.points
  1268. if (onmask_new(smallX,smallY,mask)){
  1269. if (mouseonmask_mask) {mouseonmask_mask.mouseonmask=false;}
  1270. mask.mouseonmask=true;
  1271. mouseonmask_mask = mask;
  1272. //更新显示
  1273. drawRect(x,y);
  1274. //停止搜索
  1275. found=true;
  1276. break;
  1277. }
  1278. }
  1279. if((!found)&& (mouseonrect_rect!=null)){
  1280. mouseonrect_rect.mouseonrect=false;
  1281. mouseonrect_rect=null;
  1282. drawRect(x,y);
  1283. }
  1284. if((!found)&& (mouseonmask_mask!=null)){
  1285. mouseonmask_mask.mouseonmask=false;
  1286. mouseonmask_mask=null;
  1287. drawRect(x,y);
  1288. }
  1289. }
  1290. // 判断矩形是否开始拖拽
  1291. if (isDragging == true) {
  1292. // 判断拖拽对象是否存在
  1293. if (SelectedRect != null) {
  1294. // 将圆圈移动到鼠标位置
  1295. //console.log("old(" + old_click_x1 + "," + old_click_y1 +") new(" + x + "," + y + ")");
  1296. moverect(SelectedRect, x-old_click_x1, y-old_click_y1);
  1297. old_click_x1 = x;
  1298. old_click_y1 = y;
  1299. // 更新画布
  1300. drawRect();
  1301. }else if(Selectedmask != null){
  1302. moveMask(Selectedmask, x-old_click_x1, y-old_click_y1);
  1303. old_click_x1 = x;
  1304. old_click_y1 = y;
  1305. // 更新画布
  1306. drawRect();
  1307. }
  1308. hidePopup();
  1309. }
  1310. //判断是否开始拉伸
  1311. if (stretch) {
  1312. stretchrect(SelectedRect, SelectedpointId, smallLocX(x), smallLocY(y));
  1313. drawRect();
  1314. document.getElementById("boxlabels").innerHTML=boxlabelshtml();
  1315. document.getElementById("labelcounttable").innerHTML=boxlabelcounthtml();
  1316. }
  1317. //判断mask是否开始拉伸
  1318. if (stretch_mask && SelectedmaskpointId != null) {
  1319. stretchmask(Selectedmask, SelectedmaskpointId, smallLocX(x), smallLocY(y));
  1320. drawRect();
  1321. }
  1322. if(dragging){
  1323. var dx = x - old_click_x1;
  1324. var dy = y - old_click_y1;
  1325. startx -= dx;
  1326. starty -= dy;
  1327. console.log("x=" + x + " y=" + y + " move x=" + dx + " move y=" + dy + " startx=" +startx + ",starty=" + starty);
  1328. drawRect();
  1329. old_click_x1 = x;
  1330. old_click_y1 = y;
  1331. }
  1332. };
  1333. function stopDragging() {
  1334. isDragging = false;
  1335. dragging = false;
  1336. stretch=false;
  1337. stretch_mask=false;
  1338. //console.log("choose rect 10:")
  1339. if (tocreaterect) {
  1340. drawRect(-1,-1);
  1341. }
  1342. if(showpopVar){
  1343. showpopVar= false;
  1344. document.getElementById("boxlabels").innerHTML=boxlabelshtml();
  1345. document.getElementById("labelcounttable").innerHTML=boxlabelcounthtml();
  1346. for(var i=rects.length-1; i>=0; i--) {
  1347. var rect = rects[i];
  1348. if (rect.isSelected){
  1349. xy = rect.getX1Y1X2Y2();
  1350. console.log("create rect show: x1=" + xy[0] + " y1=" + xy[1] + " x2=" + xy[2] + " y2=" + xy[3] + " startx=" + startx + ",starty=" + starty);
  1351. // wang
  1352. // var original_img_region = new file_region();
  1353. var new_region_id =i;
  1354. regions = rects;
  1355. set_region_annotations_to_default_value( new_region_id );
  1356. select_only_region(new_region_id);
  1357. showPopup(bigLocY(xy[3])+5, bigLocX(xy[2])+5 , i,"rect");
  1358. // showPopup(bigLocY(xy[3])+145, bigLocX(xy[2]) + 235, i,"rect");
  1359. //停止搜索
  1360. return;
  1361. }
  1362. }
  1363. for(var i=masks.length-1; i>=0; i--) {
  1364. var mask = masks[i];
  1365. if (mask.isSelected && mask.finish){
  1366. var new_region_id =i;
  1367. regions = masks;
  1368. select_only_region(new_region_id);
  1369. set_region_annotations_to_default_value(new_region_id);
  1370. var bound = mask.getBound();
  1371. showPopup(bigLocY(bound[3])+5, bigLocX(bound[2])+5 ,i,"mask");
  1372. // showPopup(bigLocY(bound[3])+145, bigLocX(bound[2]) + 235,i,"mask");
  1373. console.log("create mask--show...13");
  1374. //停止搜索
  1375. return;
  1376. }
  1377. }
  1378. for(var i=pointShapes.length-1; i>=0; i--) {
  1379. var pointShape = pointShapes[i];
  1380. if (pointShape.isSelected && pointShape.finish){
  1381. var new_region_id =i;
  1382. regions = pointShapes;
  1383. select_only_region(new_region_id);
  1384. set_region_annotations_to_default_value(new_region_id);
  1385. // var bound = mask.getBound();
  1386. showPopup(bigLocY(pointShape.x)+5, bigLocX(pointShape.y)+5 ,i,"pointShapes");
  1387. // showPopup(bigLocY(pointShape.x)+145, bigLocX(pointShape.y) + 235,i,"pointShapes");
  1388. console.log("create mask--show...13");
  1389. //停止搜索
  1390. return;
  1391. }
  1392. }
  1393. }
  1394. };
  1395. function updateLabelHtml(){
  1396. document.getElementById("boxlabels").innerHTML=boxlabelshtml();
  1397. document.getElementById("labelcounttable").innerHTML=boxlabelcounthtml();
  1398. }
  1399. //边栏
  1400. //任务信息
  1401. function showtaskinfo(){
  1402. $('#task_info').text(label_task_info.task_name);
  1403. $('#task_progress').text(label_task_info.task_status_desc);
  1404. var percent=label_task_info.task_status_desc.split('(')[0]
  1405. $("div[role='progressbar']").width(percent)
  1406. $("div[role='progressbar']").attr('aria-valuemax',tablePageData.total)
  1407. }
  1408. var orderType = 1;
  1409. var findLast = 0;
  1410. function showOrder(value){
  1411. console.log("--------",value)
  1412. hidePopup();
  1413. if (value == "1"){ //文件名排序
  1414. console.log("value=1")
  1415. orderType = 1;
  1416. findLast = 0;
  1417. }
  1418. else if (value == "2"){
  1419. console.log("value=2")
  1420. orderType = 0;
  1421. findLast = 0;
  1422. }
  1423. else if (value == "3"){
  1424. orderType = 0;
  1425. findLast = 3;
  1426. }
  1427. page(0,pageSize);
  1428. }
  1429. function skipLast(){
  1430. hidePopup();
  1431. if (orderType == 0){
  1432. return ;
  1433. }
  1434. findLast = 1;
  1435. page(0,pageSize);
  1436. }
  1437. function isVerified(){
  1438. if(userType == 2 && label_task_status == 1){
  1439. return true;
  1440. }
  1441. return false;
  1442. }
  1443. //显示文件列表
  1444. function showfilelist(){
  1445. var htmlstr="";
  1446. for (var i=0;i<labeltastresult.length;i++){
  1447. var fname = labeltastresult[i].pic_image_field.substring(labeltastresult[i].pic_image_field.lastIndexOf('/') + 1);
  1448. if(labeltastresult[i].pic_image_field.length > 70){
  1449. var tmpIndex = labeltastresult[i].pic_image_field.indexOf("/",70);
  1450. console.log(tmpIndex)
  1451. if(tmpIndex != -1){
  1452. fname = labeltastresult[i].pic_image_field.substring(tmpIndex + 1);
  1453. fname = fname.substring(fname.indexOf('/')+1);
  1454. }
  1455. }
  1456. var isfinished = labeltastresult[i].label_status;
  1457. if(isVerified()){
  1458. isfinished = labeltastresult[i].verify_status - 1;
  1459. }
  1460. var lablebg=" style=\"cursor:pointer\"";
  1461. var classStr = "style=\"color:#FF6200;background: transparent;border: 0;\"";
  1462. var finish="未完成";
  1463. if (isfinished=="0"){finish="已完成";classStr = "style=\"color:#27c24c;background: transparent;border: 0;\"";}
  1464. if (i==fileindex){lablebg=" style=\"color:#fff;cursor:pointer;\"";classStr = "style=\"color:#04B3E5;background: transparent;border: 0;\"";finish="标注中"}
  1465. if(isVerified()){
  1466. 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>";
  1467. }else{
  1468. 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>";
  1469. }
  1470. }
  1471. document.getElementById("filelist").innerHTML=htmlstr;
  1472. }
  1473. function changeStatus(i){
  1474. var tmpId='changeStatus_'+i;
  1475. var htmlstr= "<div class=\"panel\" style=\"background:#020004;border:0.5px solid #222324;margin-bottom:0;border-radius:0;\""
  1476. +">"
  1477. +"<label for=\"st\" style=\"padding:0.8em;color: #7092BE;\"> 标注状态修改为:</label>"+
  1478. "<select id="+tmpId+" name=\"标注状态\" style=\"text-align:center;border-radius:4px;margin-left: 1em;\">"+
  1479. "<option value=0 selected=\"\">已完成</option>"+
  1480. "<option value=1 >未完成</option>"+
  1481. "</select>"+
  1482. "<button onclick=\"updateStatus("+i+");\" class=\"btn\" style=\"padding:0;margin-left:3em;background: transparent;border:0;color:#04B3E5;\">提交</button>"
  1483. +"</div>"
  1484. document.getElementById("labelStatus").innerHTML=htmlstr;
  1485. }
  1486. // function changeStatus(i){
  1487. // var tmpId='changeStatus_'+i;
  1488. // var htmlstr= "<div class=\"panel\" style=background:#ffff;border: 1px solid rgba(0,0,0,0.2);border-radius: 6px;top:10px;"
  1489. // +">"
  1490. // +"<label for=\"st\" style=\"margin:15px;color:#333\"> 标注状态修改为:</label>"+
  1491. // "<select id="+tmpId+" name=\"标注状态\" style=\"width:100px;text-align:center;border-radius:4px;\">"+
  1492. // "<option value=0 selected=\"\">已完成</option>"+
  1493. // "<option value=1 >未完成</option>"+
  1494. // "</select>"+
  1495. // "<br />"+
  1496. // "<button onclick=\"updateStatus("+i+");\" class=\"btn btn-default\" style=\"margin:0 auto;display: block;border-radius:5px;width: 50px;\">提交</button>"
  1497. // +"</div>"
  1498. // document.getElementById("labelStatus").innerHTML=htmlstr;
  1499. // }
  1500. function changeVerifyStatus(i){
  1501. var tmpId='changeStatus_'+i;
  1502. var htmlstr= "<div class=\"panel\" style=background:#ffff;border: 1px solid rgba(0,0,0,0.2);border-radius: 6px;top:10px;"
  1503. +">"
  1504. +"<label for=\"st\" style=\"margin:15px;color:#333\"> 审核状态修改为:</label>"+
  1505. "<select id="+tmpId+" name=\"审核状态\" style=\"width:100px;text-align:center;border-radius:4px;\">"+
  1506. "<option value=1 selected=\"\">已完成</option>"+
  1507. "<option value=0 >未完成</option>"+
  1508. "</select>"+
  1509. "<br />"+
  1510. "<button onclick=\"updateVerifyStatus("+i+");\" class=\"btn btn-default\" style=\"margin:0 auto;display: block;border-radius:5px;width: 50px;\">提交</button>"
  1511. +"</div>"
  1512. document.getElementById("labelStatus").innerHTML=htmlstr;
  1513. }
  1514. function updateStatus(i){
  1515. var status_id = 'changeStatus_'+i;
  1516. var label_status=document.getElementById(status_id).value;
  1517. labeltastresult[fileindex].label_status = label_status;
  1518. $.ajax({
  1519. type:"PATCH",
  1520. url:ip + "/gitea/label-task-item-status/",
  1521. contentType:'application/json',
  1522. headers: {
  1523. authorization:token,
  1524. },
  1525. dataType:"json",
  1526. async:false,
  1527. data:JSON.stringify({'id':labeltastresult[fileindex].id,
  1528. 'label_task_id':label_task_info.id,
  1529. 'label_status':label_status,
  1530. }),
  1531. success:function(json){
  1532. showfilelist();
  1533. document.getElementById("labelStatus").innerHTML = "";
  1534. return true;
  1535. },
  1536. error:function(response) {
  1537. redirect(response);
  1538. }
  1539. });
  1540. }
  1541. function updateVerifyStatus(i){
  1542. var status_id = 'changeStatus_'+i;
  1543. var verify_status=document.getElementById(status_id).value;
  1544. labeltastresult[fileindex].verify_status = verify_status;
  1545. $.ajax({
  1546. type:"PATCH",
  1547. url:ip + "/gitea/label-task-item-verify-status/",
  1548. contentType:'application/json',
  1549. headers: {
  1550. authorization:token,
  1551. },
  1552. dataType:"json",
  1553. async:false,
  1554. data:JSON.stringify({'id':labeltastresult[fileindex].id,
  1555. 'label_task_id':label_task_info.id,
  1556. 'verify_status':verify_status,
  1557. }),
  1558. success:function(json){
  1559. showfilelist();
  1560. document.getElementById("labelStatus").innerHTML = "";
  1561. return true;
  1562. },
  1563. error:function(response) {
  1564. redirect(response);
  1565. }
  1566. });
  1567. }
  1568. //this.id =""; //标识
  1569. //this.blurred=false;//模糊不清的; 记不清的; 难以区分的; 模棱两可的
  1570. //this.goodIllumination = true; //照明
  1571. //this.frontview = true;//正面图
  1572. function parse_labelinfo(labelinfo){
  1573. rects.length = 0;
  1574. masks.length = 0;
  1575. pointShapes.length = 0;
  1576. if(!isEmpty(labelinfo)){
  1577. // console.log("标注信息:"+labelinfo);
  1578. var label_arr = JSON.parse(labelinfo);
  1579. for(var i=0;i<label_arr.length;i++){
  1580. if(!isEmpty(label_arr[i].mask)){
  1581. cls=label_arr[i].class_name;
  1582. var tmpMask = new maskar(getCanvasLocationX(label_arr[i].mask[0]),getCanvasLocationY(label_arr[i].mask[1]),cls);
  1583. for(var j = 2; j < label_arr[i].mask.length; j+=2){
  1584. tmpMask.points.push(new point(getCanvasLocationX(label_arr[i].mask[j]),getCanvasLocationY(label_arr[i].mask[j+1])));
  1585. }
  1586. if(!isEmpty(label_arr[i].id)){
  1587. tmpMask.id= label_arr[i].id;
  1588. }
  1589. if(!isEmpty(label_arr[i].blurred)){
  1590. tmpMask.blurred = label_arr[i].blurred;
  1591. }
  1592. if(!isEmpty(label_arr[i].goodIllumination)){
  1593. tmpMask.goodIllumination = label_arr[i].goodIllumination;
  1594. }
  1595. if(!isEmpty(label_arr[i].frontview)){
  1596. tmpMask.frontview = label_arr[i].frontview;
  1597. }
  1598. if(!isEmpty(label_arr[i].other)){
  1599. tmpMask.other = label_arr[i].other;
  1600. }else if (isEmpty(label_arr[i].other)){
  1601. tmpMask.other["region_attributes"]["type"] = tmpMask.type;
  1602. tmpMask.other["region_attributes"]["id"] = tmpMask.id;
  1603. }
  1604. tmpMask.finish = true;
  1605. if (maxIdNum< parseInt(tmpMask.other["region_attributes"]["id"])){
  1606. maxIdNum = parseInt(tmpMask.other["region_attributes"]["id"]);
  1607. }
  1608. masks.push(tmpMask);
  1609. }
  1610. else if(!isEmpty(label_arr[i].box)){
  1611. x1 = getCanvasLocationX(label_arr[i].box[0]);
  1612. y1 = getCanvasLocationY(label_arr[i].box[1]);
  1613. x2 = getCanvasLocationX(label_arr[i].box[2]);
  1614. y2 = getCanvasLocationY(label_arr[i].box[3]);
  1615. cls=label_arr[i].class_name;
  1616. score = label_arr[i].score;
  1617. var rect = new rectar(x1,y1,x2,y2,cls,score);
  1618. if(!isEmpty(label_arr[i].id)){
  1619. rect.id= label_arr[i].id;
  1620. }
  1621. if(!isEmpty(label_arr[i].blurred)){
  1622. rect.blurred = label_arr[i].blurred;
  1623. }
  1624. if(!isEmpty(label_arr[i].goodIllumination)){
  1625. rect.goodIllumination = label_arr[i].goodIllumination;
  1626. }
  1627. if(!isEmpty(label_arr[i].frontview)){
  1628. rect.frontview = label_arr[i].frontview;
  1629. }
  1630. if(!isEmpty(label_arr[i].other)){
  1631. rect.other = label_arr[i].other;
  1632. }
  1633. // else if (isEmpty(label_arr[i].other) && (isEmpty(label_attributes) || Object.keys(label_attributes).length == 0)){
  1634. else if (isEmpty(label_arr[i].other)){
  1635. rect.other["region_attributes"]["type"] = rect.type;
  1636. rect.other["region_attributes"]["id"] = rect.id;
  1637. }
  1638. if (maxIdNum< parseInt(rect.other["region_attributes"]["id"])){
  1639. maxIdNum = parseInt(rect.other["region_attributes"]["id"]);
  1640. }
  1641. rects.push(rect);
  1642. }
  1643. else if(!isEmpty(label_arr[i].keypoints)){
  1644. cls=label_arr[i].class_name;
  1645. score = label_arr[i].score;
  1646. var pointShapeObj = new pointShape(getCanvasLocationX(label_arr[i].keypoints[0]),getCanvasLocationY(label_arr[i].keypoints[1]),cls,score);
  1647. if(!isEmpty(label_arr[i].other)){
  1648. pointShapeObj.other = label_arr[i].other;
  1649. }
  1650. else if (isEmpty(label_arr[i].other)){
  1651. pointShapeObj.other["region_attributes"]["type"] = pointShapeObj.type;
  1652. pointShapeObj.other["region_attributes"]["id"] = pointShapeObj.id;
  1653. }
  1654. if (maxIdNum< parseInt(pointShapeObj.other["region_attributes"]["id"])){
  1655. maxIdNum = parseInt(pointShapeObj.other["region_attributes"]["id"]);
  1656. }
  1657. pointShapes.push(pointShapeObj);
  1658. }
  1659. }
  1660. //console.log(rects);
  1661. //console.log(masks);
  1662. }
  1663. document.getElementById("boxlabels").innerHTML=boxlabelshtml();
  1664. document.getElementById("labelcounttable").innerHTML=boxlabelcounthtml();
  1665. // 加载值:需要打开已有属性和属性值,需要回传_via_attributes, _via_img_metadata两个值的获取
  1666. //暂时默认设置只有类别属性
  1667. set_display_area_content( VIA_DISPLAY_AREA_CONTENT_NAME.IMAGE );
  1668. }
  1669. function getHtmlStr(shape,shapetype,rectIndex){
  1670. var lablebg="";
  1671. if (shape.isSelected){
  1672. lablebg=" style=\"background:#eee;color:#5a5a5a;\"";
  1673. var tmp = "tr_" + shapetype + "_" + Math.max(rectIndex-1,0);
  1674. var $objTr = $("#"+tmp) ; //找到要定位的地方 tr
  1675. var objTr = $objTr[0]; //转化为dom对象
  1676. if (!isEmpty(objTr)){
  1677. $("#labelpanel").animate({scrollTop:objTr.offsetTop},0); //滚动条滚动
  1678. }
  1679. }
  1680. var tmpType = shape.type;
  1681. //console.log("tmpType =" + tmpType);
  1682. if(!isEmpty(shape.other["region_attributes"]["type"])){
  1683. tmpType = shape.other["region_attributes"]["type"];
  1684. }
  1685. var shapeswidthHeigth = "";
  1686. if (shapetype == "bbox"){
  1687. xywh = shape.getXYWH();
  1688. shapeswidthHeigth = getRealLocationX(xywh[2]) + "," + getRealLocationY(xywh[3]);
  1689. }
  1690. var xy=shape.points;
  1691. var x ;
  1692. var y ;
  1693. if (shapetype == "point"){
  1694. x = shape.x;
  1695. y = shape.y;
  1696. }
  1697. else{
  1698. x = xy[0].x;
  1699. y = xy[0].y;
  1700. }
  1701. 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>";
  1702. }
  1703. function setStyle(rectIndex,shapetype){
  1704. for (var i=0;i<rects.length;i++){
  1705. document.getElementById("tr_bbox_" + i).style = "";
  1706. }
  1707. for (var i=0;i<pointShapes.length;i++){
  1708. document.getElementById("tr_point_" + i).style = "";
  1709. }
  1710. for (var i=0;i<masks.length;i++){
  1711. document.getElementById("tr_mask_" + i).style = "";
  1712. }
  1713. document.getElementById("tr_" + shapetype + "_" + rectIndex).style = "background:#eee;color:#5a5a5a;";
  1714. }
  1715. function highlight(x,y,rectIndex,shapetype){
  1716. setStyle(rectIndex,shapetype);
  1717. Selectedmask = null;
  1718. SelectedRect = null;
  1719. SelectedPointShape = null;
  1720. if (shapetype=="bbox"){
  1721. for (var i=0;i<rects.length;i++){
  1722. rects[i].isSelected = false;
  1723. if (i==rectIndex){
  1724. rects[i].isSelected = true;
  1725. SelectedRect = rects[i];
  1726. }
  1727. }
  1728. for (var i=0;i<pointShapes.length;i++){
  1729. pointShapes[i].isSelected = false;
  1730. }
  1731. for (var i=0;i<masks.length;i++){
  1732. masks[i].isSelected = false;
  1733. }
  1734. }
  1735. else if (shapetype=="point"){
  1736. for (var i=0;i<rects.length;i++){
  1737. rects[i].isSelected = false;
  1738. }
  1739. for (var i=0;i<pointShapes.length;i++){
  1740. pointShapes[i].isSelected = false;
  1741. if (i==rectIndex){
  1742. pointShapes[i].isSelected = true;
  1743. SelectedPointShape = pointShapes[i];
  1744. }
  1745. }
  1746. for (var i=0;i<masks.length;i++){
  1747. masks[i].isSelected = false;
  1748. }
  1749. }
  1750. else{
  1751. SelectedRect = null;
  1752. for (var i=0;i<rects.length;i++){
  1753. rects[i].isSelected = false;
  1754. }
  1755. for (var i=0;i<pointShapes.length;i++){
  1756. pointShapes[i].isSelected = false;
  1757. }
  1758. for (var i=0;i<masks.length;i++){
  1759. masks[i].isSelected = false;
  1760. if (i==rectIndex){
  1761. masks[i].isSelected = true;
  1762. Selectedmask = masks[i];
  1763. }
  1764. }
  1765. }
  1766. drawRect();
  1767. }
  1768. function boxlabelshtml(){
  1769. var htmlstr="";
  1770. for (var i=0;i<rects.length;i++){
  1771. htmlstr = htmlstr + getHtmlStr(rects[i],'bbox',i);
  1772. }
  1773. for (var i=0;i<masks.length;i++){
  1774. htmlstr = htmlstr + getHtmlStr(masks[i],'mask',i);
  1775. }
  1776. for(var i = 0; i < pointShapes.length; i++){
  1777. htmlstr = htmlstr + getHtmlStr(pointShapes[i],'point',i);
  1778. }
  1779. return htmlstr;
  1780. }
  1781. function boxlabelCount(labelMap,shape){
  1782. var tmpType = shape.type;
  1783. if(!isEmpty(shape.other["region_attributes"]["type"])){
  1784. tmpType = shape.other["region_attributes"]["type"];
  1785. }
  1786. if(labelMap[tmpType] == null){
  1787. labelMap[tmpType] = 1;
  1788. }else{
  1789. labelMap[tmpType] = labelMap[tmpType] + 1;
  1790. }
  1791. }
  1792. function boxlabelcounthtml(){
  1793. var htmlstr="";
  1794. var labelMap = {};
  1795. for (var i=0;i<rects.length;i++){
  1796. boxlabelCount(labelMap,rects[i]);
  1797. }
  1798. for (var i=0;i<masks.length;i++){
  1799. boxlabelCount(labelMap,masks[i]);
  1800. }
  1801. for (var i=0;i<pointShapes.length;i++){
  1802. boxlabelCount(labelMap,pointShapes[i]);
  1803. }
  1804. for (item in labelMap){
  1805. htmlstr = htmlstr + "<tr><td style=\"width:10px\"></td> <td>"+ item + "</td><td>" + labelMap[item] +"</td></tr>";
  1806. }
  1807. return htmlstr;
  1808. }
  1809. function getRealLocationX(num){
  1810. var loc = Math.round(num*img.width/canvas.width);
  1811. // if (img.width<600){
  1812. // loc = Math.round(num);
  1813. // }
  1814. if(loc <= 0){
  1815. loc = 1;
  1816. }
  1817. if(loc > img.width){
  1818. loc = img.width -1;
  1819. }
  1820. return loc;
  1821. }
  1822. function getRealLocationY(num){
  1823. var loc = Math.round(num*img.height/canvas.height);
  1824. // if (img.width<600){
  1825. // loc = Math.round(num);
  1826. // }
  1827. if(loc <= 0){
  1828. loc = 1;
  1829. }
  1830. if( loc > img.height){
  1831. loc = img.height -1;
  1832. }
  1833. return loc;
  1834. }
  1835. function getCanvasLocationX(num){
  1836. return Math.round(num*canvas.width/parseInt(img.width));
  1837. }
  1838. function getCanvasLocationY(num){
  1839. return Math.round(num*canvas.height/parseInt(img.height));
  1840. }
  1841. function setAutoModel(){
  1842. hidePopup();
  1843. loadModel();
  1844. display_createlabel();
  1845. }
  1846. var algModelList;
  1847. function loadModel(){
  1848. $.ajax({
  1849. type:"GET",
  1850. contentType:'application/json',
  1851. url: ip + "/api/queryAlgModelForHandLabel/",
  1852. dataType:"json",
  1853. async:false,
  1854. headers: {
  1855. // Accept: "text/html; q=1.0",
  1856. authorization:token,
  1857. },
  1858. // enctype:"multipart/form-data",
  1859. success:function(jsonList){
  1860. console.log(jsonList);
  1861. algModelList = jsonList;
  1862. // return json.token;
  1863. },
  1864. error:function(response) {
  1865. redirect(response);
  1866. }
  1867. });
  1868. }
  1869. function display_createlabel(){
  1870. var html="<option value=\"\" selected=\"\">请选择</option>";
  1871. for (var i=0;i<algModelList.length;i++){
  1872. if (i==2){
  1873. var row = "<option selected value=\""+algModelList[i].id+
  1874. "\">"+algModelList[i].model_name+
  1875. "</option>";
  1876. }
  1877. else{
  1878. var row = "<option value=\""+algModelList[i].id+
  1879. "\">"+algModelList[i].model_name+
  1880. "</option>";
  1881. }
  1882. html=html+row;
  1883. }
  1884. console.log(html);
  1885. $('#tracking_startid').val('1');
  1886. $('#tracking_endid').val(tablePageData.total);
  1887. document.getElementById('predict_model').innerHTML=html;
  1888. document.getElementById("tracking_startid_div").style.display="none";
  1889. document.getElementById("tracking_endid_div").style.display="none";
  1890. document.getElementById("label_id_div").style.display="none";
  1891. document.getElementById("labelOption_div").style.display="none";
  1892. //document.getElementById("labelOption").innerHTML="<option value=\"2\" selected=\"\">请选择</option> <option value=\"3\">识别车的类型与颜色</option>";
  1893. document.getElementById('predtask_id').disabled=false;
  1894. $('#label_id').val('1');
  1895. bar.style.width='1%';
  1896. document.getElementById('text-progress').innerHTML='0%';
  1897. }
  1898. function submit_predtask(){
  1899. var item_id = labeltastresult[fileindex].id;
  1900. var predict_model_val = $('#predict_model').val();
  1901. if(isEmpty(predict_model_val)){
  1902. alert("请选择标注任务使用的模型。");
  1903. return;
  1904. }
  1905. if(labeltastresult[fileindex].label_status == 0 && !(predict_model_val == 12 || predict_model_val == 16 || predict_model_val == 20 || predict_model_val == 21)){
  1906. alert("标注状态已经完成,不能进行自动检测。");
  1907. return;
  1908. }
  1909. var task_type = "1";
  1910. var start_id = 0;
  1911. var end_id = 0;
  1912. var label_id = 1;
  1913. var label_option = null;
  1914. if(predict_model_val == 12 || predict_model_val == 16 || predict_model_val == 20 || predict_model_val == 21){
  1915. task_type = "2";
  1916. start_id = $('#tracking_startid').val();
  1917. end_id = $('#tracking_endid').val();
  1918. label_id = $('#label_id').val();
  1919. if(start_id < 1 || start_id > tablePageData.total){
  1920. alert("请输入正确的追踪起始图片ID,范围为1到" + tablePageData.total);
  1921. return;
  1922. }
  1923. if(end_id < 1 || end_id > tablePageData.total){
  1924. alert("请输入正确的追踪结束图片ID,范围为1到" + tablePageData.total);
  1925. return;
  1926. }
  1927. if(label_id < 1){
  1928. alert("标注框ID为大于等于1的整数。");
  1929. return;
  1930. }
  1931. }
  1932. document.getElementById('predtask_id').disabled=true;
  1933. $.ajax({
  1934. type:"POST",
  1935. url:ip + "/gitea/auto-label-task",
  1936. contentType:'application/json',
  1937. headers: {
  1938. authorization:token,
  1939. },
  1940. dataType:"json",
  1941. async:false,
  1942. data:JSON.stringify({'label_task_id':item_id,
  1943. 'model':predict_model_val,
  1944. 'pic_object_name' : img.width + "," + img.height,
  1945. 'task_type':task_type,
  1946. 'startIndex':start_id,
  1947. 'endIndex':end_id,
  1948. 'taskId':label_task,
  1949. 'label_id':label_id,
  1950. 'label_option':label_option
  1951. }),
  1952. success:function(res){
  1953. console.log('创建数据信息');
  1954. },
  1955. error:function(response) {
  1956. redirect(response);
  1957. }
  1958. });
  1959. setIntervalToDo();
  1960. }
  1961. var timeId;
  1962. var count;
  1963. var progress;
  1964. function setIntervalToDo(){
  1965. count=0;
  1966. timeId = self.setInterval("clock()",1000);//5秒刷新
  1967. console.log("开始刷新。timeId=" + timeId);
  1968. }
  1969. function clock(){
  1970. count++;
  1971. if(count > 600 ){
  1972. console.log("清除定时器。timeId=" + timeId);
  1973. window.clearInterval(timeId);
  1974. timeId = null;
  1975. $("#autoLabel").modal('hide');
  1976. return;
  1977. }
  1978. $.ajax({
  1979. type:"GET",
  1980. url:ip + "/api/query-auto-label-task-progress/",
  1981. headers: {
  1982. authorization:token,
  1983. },
  1984. dataType:"json",
  1985. data:{'taskId': label_task},
  1986. async:false,
  1987. success:function(json){
  1988. progress = json;
  1989. console.log(json);
  1990. },
  1991. error:function(response) {
  1992. progress = null;
  1993. console.log("query progress error");
  1994. redirect(response);
  1995. }
  1996. });
  1997. if(isEmpty(progress)){
  1998. console.log("清除定时器。timeId=" + timeId);
  1999. bar.style.width='100%';
  2000. document.getElementById('text-progress').innerHTML='100%';
  2001. window.clearInterval(timeId);
  2002. timeId = null;
  2003. var current = $('#displayPage1').text();
  2004. $("#autoLabel").modal('hide');
  2005. console.log("开始获取结果。current=" + current);
  2006. if(current >= 1){
  2007. pageReload(current - 1,pageSize,fileindex);
  2008. }
  2009. }else{
  2010. //更新进度
  2011. var iSpeed = progress.progress;
  2012. bar.style.width=iSpeed+'%';
  2013. document.getElementById('text-progress').innerHTML=iSpeed+'%'
  2014. }
  2015. /*
  2016. var current = $('#displayPage1').text();
  2017. console.log("开始刷新。current=" + current);
  2018. if(current >= 1){
  2019. pageReload(current - 1,pageSize,fileindex);
  2020. if(!isEmpty(labeltastresult[fileindex].label_info)){
  2021. window.clearInterval(timeId);
  2022. timeId = null;
  2023. }
  2024. }
  2025. */
  2026. }
  2027. function submit_deletelabel(){
  2028. var start_id = $('#delete_startid').val();
  2029. var end_id = $('#delete_endid').val();
  2030. if(start_id < 1 || start_id > tablePageData.total){
  2031. alert("请输入正确的起始图片ID,范围为1到" + tablePageData.total);
  2032. return;
  2033. }
  2034. if(end_id < 1 || end_id > tablePageData.total){
  2035. alert("请输入正确的结束图片ID,范围为1到" + tablePageData.total);
  2036. return;
  2037. }
  2038. //var one_reid_name = $('#one_reid_name').val();
  2039. $.ajax({
  2040. type:"POST",
  2041. url:ip + "/gitea/label-task-delete-label",
  2042. headers: {
  2043. authorization:token,
  2044. },
  2045. dataType:"json",
  2046. async:false,
  2047. data:{'label_task_id':label_task_info.id,
  2048. 'start_id':start_id,
  2049. 'end_id' : end_id
  2050. //'one_reid_name':one_reid_name
  2051. },
  2052. success:function(res){
  2053. console.log('创建数据信息');
  2054. },
  2055. error:function(response) {
  2056. redirect(response);
  2057. }
  2058. });
  2059. $("#deleteLabel").modal('hide');
  2060. var current = $('#displayPage1').text();
  2061. if(current >= 1){
  2062. pageReload(current - 1,pageSize,fileindex);
  2063. }
  2064. }
  2065. function updatelabel(fileindex){
  2066. var label_list=[]
  2067. for (var i=0;i<rects.length;i++){
  2068. x1y1x2y2=rects[i].getX1Y1X2Y2();
  2069. rects[i].type = '';//regions[i].other.["region_attributes"]["type"];
  2070. var label= {'class_name':rects[i].type, "score":1.0};
  2071. if(!isEmpty(rects[i].other.region_attributes.type)){
  2072. label['class_name'] = rects[i].other.region_attributes.type;
  2073. }
  2074. if(!isEmpty(rects[i].other.region_attributes.id)){
  2075. rects[i].id = rects[i].other.region_attributes.id;
  2076. }
  2077. var xmin = getRealLocationX(x1y1x2y2[0]);
  2078. var ymin = getRealLocationY(x1y1x2y2[1]);
  2079. var xmax = getRealLocationX(x1y1x2y2[2]);
  2080. var ymax = getRealLocationY(x1y1x2y2[3]);
  2081. label['box']=[xmin,ymin, xmax,ymax];
  2082. if(isEmpty(rects[i].id)){
  2083. label['id'] = i+'';
  2084. }else{
  2085. label['id'] = rects[i].id+'';
  2086. }
  2087. label['blurred']=rects[i].blurred;
  2088. label['goodIllumination']=rects[i].goodIllumination;
  2089. label['frontview']=rects[i].frontview;
  2090. label['other']=rects[i].other;
  2091. //console.log(label);
  2092. label_list.push(label);
  2093. }
  2094. for (var i=0;i<masks.length;i++){
  2095. masks[i].type = '';//regions[i].other.["region_attributes"]["type"];
  2096. var label = {'class_name':masks[i].type, "score":1.0};
  2097. if(!isEmpty(masks[i].other.region_attributes.type)){
  2098. label['class_name'] = masks[i].other.region_attributes.type;
  2099. }
  2100. if(!isEmpty(masks[i].other.region_attributes.id)){
  2101. masks[i].id = masks[i].other.region_attributes.id;
  2102. }
  2103. var labelMaskList = [];
  2104. for(var j = 0; j < masks[i].points.length; j++){
  2105. labelMaskList.push(getRealLocationX(masks[i].points[j].x));
  2106. labelMaskList.push(getRealLocationY(masks[i].points[j].y));
  2107. }
  2108. label['mask'] = labelMaskList;
  2109. label['id'] = masks[i].id+'';
  2110. label['blurred']=masks[i].blurred;
  2111. label['goodIllumination']=masks[i].goodIllumination;
  2112. label['frontview']=masks[i].frontview;
  2113. label['other']=masks[i].other;
  2114. //console.log(label);
  2115. label_list.push(label);
  2116. }
  2117. for (var i=0;i<pointShapes.length;i++){
  2118. pointShapes[i].type = '';//regions[i].other.["region_attributes"]["type"];
  2119. var label = {'class_name':pointShapes[i].type, "score":1.0};
  2120. if(!isEmpty(pointShapes[i].other.region_attributes.type)){
  2121. label['class_name'] = pointShapes[i].other.region_attributes.type;
  2122. }
  2123. if(!isEmpty(pointShapes[i].other.region_attributes.id)){
  2124. pointShapes[i].id = pointShapes[i].other.region_attributes.id;
  2125. }
  2126. var pointList = [];
  2127. pointList.push(getRealLocationX(pointShapes[i].x));
  2128. pointList.push(getRealLocationY(pointShapes[i].y));
  2129. pointList.push(2);//0表示这个关键点没有标注(这种情况下x=y=v=0),1表示这个关键点标注了但是不可见(被遮挡了),2 表示这个关键点标注了同时也可见
  2130. label['keypoints'] = pointList;
  2131. label['id'] = pointShapes[i].id+'';
  2132. label['blurred']=pointShapes[i].blurred;
  2133. label['goodIllumination']=pointShapes[i].goodIllumination;
  2134. label['frontview']=pointShapes[i].frontview;
  2135. label['other']=pointShapes[i].other;
  2136. //console.log(label);
  2137. label_list.push(label);
  2138. }
  2139. labelinfo_jsonstr = JSON.stringify(label_list);
  2140. labeltastresult[fileindex].label_info=labelinfo_jsonstr;
  2141. var flag = 0;
  2142. if(isVerified()){
  2143. labeltastresult[fileindex].verify_status=1;
  2144. flag = 100;
  2145. }else{
  2146. if(label_list.length > 0){
  2147. labeltastresult[fileindex].label_status=0;
  2148. }
  2149. else{
  2150. labeltastresult[fileindex].label_status=1;
  2151. }
  2152. }
  2153. $.ajax({
  2154. type:"PATCH",
  2155. url:ip + "/gitea/label-task-item/",
  2156. contentType:'application/json',
  2157. headers: {
  2158. authorization:token,
  2159. },
  2160. dataType:"json",
  2161. async:false,
  2162. data:JSON.stringify({'id':labeltastresult[fileindex].id,
  2163. 'label_task_id':label_task_info.id,
  2164. 'label_info':labelinfo_jsonstr,
  2165. 'label_status': labeltastresult[fileindex].label_status,
  2166. 'verify_status': labeltastresult[fileindex].verify_status,
  2167. 'pic_object_name' : img.width + "," + img.height,
  2168. 'display_order2':flag
  2169. }),
  2170. success:function(json){
  2171. return true;
  2172. },
  2173. error:function(response) {
  2174. redirect(response);
  2175. }
  2176. });
  2177. return false;
  2178. }
  2179. function get_labeltask(){
  2180. console.log('query labeltask info.');
  2181. $.ajax({
  2182. type:"GET",
  2183. url:ip + "/gitea/label-task/"+label_task+"/",
  2184. headers: {
  2185. authorization:token,
  2186. },
  2187. dataType:"json",
  2188. async:false,
  2189. success:function(json){
  2190. label_task_info = json;
  2191. console.log('return labeltask info.' + label_task_info);
  2192. page(0,pageSize);
  2193. },
  2194. error:function(response) {
  2195. redirect(response);
  2196. }
  2197. });
  2198. }
  2199. function update_labeltask(task_label_type_info){
  2200. console.log("label_task_id=" + label_task_info.id);
  2201. console.log("task_label_type_info=" + task_label_type_info);
  2202. $.ajax({
  2203. type:"PATCH",
  2204. url:ip + "/gitea/label-task/",
  2205. headers: {
  2206. authorization:token,
  2207. },
  2208. dataType:"json",
  2209. data:{
  2210. 'label_task_id':label_task_info.id,
  2211. 'task_label_type_info':task_label_type_info,
  2212. },
  2213. async:false,
  2214. success:function(json){
  2215. console.log(json);
  2216. },
  2217. error:function(response) {
  2218. redirect(response);
  2219. }
  2220. });
  2221. }
  2222. function list(current,pageSize,index=0){
  2223. $.ajax({
  2224. type:"GET",
  2225. url:ip + "/gitea/label-task-item-page/",
  2226. headers: {
  2227. authorization:token,
  2228. },
  2229. dataType:"json",
  2230. data:{
  2231. 'label_task':label_task_info.id,
  2232. 'startPage':current,
  2233. 'pageSize':pageSize,
  2234. 'orderType': orderType,
  2235. 'findLast':findLast,
  2236. },
  2237. async:false,
  2238. success:function(json){
  2239. tablePageData = json;
  2240. tableData = json.data;
  2241. labeltastresult = tableData;
  2242. fileindex=index;
  2243. if(lastindex){
  2244. fileindex = pageSize - 1;
  2245. }
  2246. //console.log(json);
  2247. // return json.token;
  2248. },
  2249. error:function(response) {
  2250. redirect(response);
  2251. }
  2252. });
  2253. }
  2254. var pageSize = 20;
  2255. var tableData;
  2256. var tablePageData;
  2257. function pageReload(current,pageSize,fileindex){
  2258. list(current,pageSize,fileindex);
  2259. loadimg();
  2260. showtaskinfo();
  2261. showfilelist();
  2262. //display_list();
  2263. setPage(tablePageData,pageSize);
  2264. }
  2265. function page(current,pageSize){
  2266. list(current,pageSize);
  2267. loadimg();
  2268. showtaskinfo();
  2269. showfilelist();
  2270. //display_list();
  2271. setPage(tablePageData,pageSize);
  2272. }
  2273. function nextPage(){
  2274. hidePopup();
  2275. var current = $('#displayPage1').text();
  2276. console.log("current=" + current);
  2277. findLast = 0;
  2278. page(current,pageSize);
  2279. }
  2280. function prePage(){
  2281. hidePopup();
  2282. var current =$('#displayPage1').text();
  2283. console.log("current=" + current);
  2284. if(current > 1){
  2285. console.log("current=" + (current - 2));
  2286. findLast = 0;
  2287. page(current - 2,pageSize);
  2288. }
  2289. }
  2290. function goPage(){
  2291. hidePopup();
  2292. var goNum = $('#goNum').val();
  2293. findLast = 0;
  2294. var pageTotal = $("#totalNum").text();
  2295. var pageNum = parseInt(pageTotal/pageSize);
  2296. if(pageTotal%pageSize!=0){
  2297. pageNum += 1;
  2298. }else {
  2299. pageNum = pageNum;
  2300. }
  2301. if (goNum<=0){
  2302. alert("请输入大于0的数值");
  2303. }
  2304. else if(goNum<=pageNum){
  2305. page(goNum - 1,pageSize);
  2306. }
  2307. else{
  2308. alert("不能超出总页码!");
  2309. }
  2310. }
  2311. $("#goNum").keydown(function (e) {
  2312. if (e.keyCode == 13) {
  2313. goPage();
  2314. }
  2315. });
  2316. function setPage(pageData,pageSize){
  2317. var startIndex = pageData.current * pageSize;
  2318. if(startIndex < 10){
  2319. $('#startIndex').text(" " + (pageData.current * pageSize + 1));
  2320. }else{
  2321. $('#startIndex').text(pageData.current * pageSize + 1);
  2322. }
  2323. var endIndex = pageData.current * pageSize + pageData.data.length;
  2324. if(endIndex < 10){
  2325. $('#endIndex').text(" " + (pageData.current * pageSize + pageData.data.length));
  2326. }else{
  2327. $('#endIndex').text(pageData.current * pageSize + pageData.data.length);
  2328. }
  2329. $('#totalNum').text(pageData.total);
  2330. $('#displayPage1').text(pageData.current + 1);
  2331. console.log("set prePage status, pageData.current=" + pageData.current);
  2332. if(pageData.current == 0){
  2333. console.log("set prePage disabled.");
  2334. $('#prePage').removeAttr("href");
  2335. $('#prePage').attr('style','color:#000;margin-right:1em;');
  2336. }
  2337. else{
  2338. $('#prePage').attr("href","javascript:prePage()");
  2339. $('#prePage').attr('style','color:#f5f5f6;margin-right:1em;');
  2340. }
  2341. if((pageData.current + 1) * pageSize >= pageData.total){
  2342. console.log("set nextPage disabled.");
  2343. $('#nextPage').removeAttr("href");
  2344. $('#nextPage').attr('style','color:#000;margin-left:1em;')
  2345. }
  2346. else{
  2347. $('#nextPage').attr("href","javascript:nextPage()");
  2348. $('#nextPage').attr('style','color:#f5f5f6;margin-left:1em;');
  2349. }
  2350. var pageTotal = pageData.total;
  2351. var pageNum = parseInt(pageTotal/pageSize);
  2352. if(pageTotal%pageSize!=0){
  2353. pageNum += 1;
  2354. }else {
  2355. pageNum = pageNum;
  2356. }
  2357. $("#totalPageNum").text(pageNum);
  2358. }
  2359. init_index();
  2360. // canvas = document.getElementById("myCanvas");
  2361. // context = canvas.getContext("2d");
  2362. // var maxWidth = document.getElementById("showPic").offsetWidth;
  2363. // var maxHeight = document.getElementById("showPic").offsetHeight-100;
  2364. // canvas.width = maxWidth;//document.getElementById("tool0").offsetWidth;
  2365. // canvas.height = maxHeight;//document.getElementById("tool0").offsetWidth/1280*720;
  2366. // show_region = document.getElementById("show_region");
  2367. // show_region.width =document.getElementById("tool0").offsetWidth;
  2368. // show_region.height = document.getElementById("tool0").offsetWidth/1280*720;
  2369. function init_index() {
  2370. canvas = document.getElementById("myCanvas");
  2371. context = canvas.getContext("2d");
  2372. maxWidth = document.getElementById("showPic").offsetWidth;
  2373. maxHeight = document.getElementById("showPic").offsetHeight-100;
  2374. canvas.width = maxWidth;
  2375. canvas.height = maxHeight;
  2376. canvas.onmousedown = canvasClick;
  2377. canvas.onmouseup = stopDragging;
  2378. canvas.onmouseout = stopDragging;
  2379. canvas.onmousemove =dragRect;
  2380. var token = getSessionStorageMessage("token");
  2381. console.log("page load token=" + token);
  2382. if(!isEmpty(token)){
  2383. console.log("this is not null.token =" + token);
  2384. doLoad();
  2385. }
  2386. };
  2387. function doLoad(){
  2388. token = getSessionStorageMessage("token");
  2389. userType = getSessionStorageMessage("userType");
  2390. if(typeof token == "undefined" || token == null || token == ""){
  2391. console.log("token=" + token);
  2392. console.log("onload tasks/detect/index.html");
  2393. window.location.href = "../../login.html";
  2394. }
  2395. label_task = getSessionStorageMessage("label_task");
  2396. label_task_status = getSessionStorageMessage("label_task_status"); //1表示审核
  2397. get_labeltask();
  2398. drawRect();
  2399. _via_init();
  2400. //加载保存好的属性结构,如果不存在,加载默认的类别信息
  2401. if(!isEmpty(label_task_info.task_label_type_info)){
  2402. label_attributes = JSON.parse(label_task_info.task_label_type_info);
  2403. }
  2404. if (isEmpty(label_attributes)){
  2405. get_init_atrribute();
  2406. }
  2407. else{
  2408. if (Object.keys(label_attributes).length == 0){
  2409. get_init_atrribute();
  2410. }
  2411. else{
  2412. _via_attributes["region"] = label_attributes;
  2413. }
  2414. }
  2415. }
  2416. function get_init_atrribute(){
  2417. _via_attributes = {'region':{}};
  2418. var atti = "id"; // 属性名
  2419. _via_attributes['region'][atti] = {};
  2420. _via_attributes['region'][atti]["type"] = "text";
  2421. _via_attributes['region'][atti]["description"] = "";
  2422. _via_attributes['region'][atti]["default_value"] = "";
  2423. atti = "type"; // 属性名
  2424. _via_attributes['region'][atti] = {};
  2425. _via_attributes['region'][atti]["type"] = "dropdown";
  2426. _via_attributes['region'][atti]["description"] = "";
  2427. _via_attributes['region'][atti]["options"] = {};
  2428. _via_attributes['region'][atti]["options"]["car"] = "car";
  2429. _via_attributes['region'][atti]["options"]["person"] = "person";
  2430. _via_attributes['region'][atti]["options"]["non-motor"] = "non-motor";
  2431. _via_attributes['region'][atti]["default_options"] = {};
  2432. }
  2433. function model_sele_Change(event){
  2434. var modelid = $('#predict_model option:selected').val();
  2435. console.log("predict_model=" + modelid);
  2436. if(modelid == 12 || modelid == 16 || modelid == 20 || modelid == 21){
  2437. document.getElementById("tracking_startid_div").style.display="block";
  2438. document.getElementById("tracking_endid_div").style.display="block";
  2439. document.getElementById("labelOption_div").style.display="block";
  2440. if(modelid == 12 || modelid == 16){
  2441. document.getElementById("label_id_div").style.display="block";
  2442. }else{
  2443. document.getElementById("label_id_div").style.display="none";
  2444. }
  2445. if(modelid == 21){
  2446. document.getElementById("labelOption").innerHTML="<option value=\"10\" selected=\"\">person</option> <option value=\"11\">car</option>";
  2447. }else if(modelid == 20){
  2448. document.getElementById("labelOption").innerHTML="<option value=\"10\" selected=\"\">person</option>";
  2449. }else{
  2450. document.getElementById("labelOption").innerHTML="<option value=\"0\" selected=\"\">合并已有的标注信息</option> <option value=\"1\">删除已有的标注信息</option>";
  2451. }
  2452. }else{
  2453. document.getElementById("tracking_startid_div").style.display="none";
  2454. document.getElementById("tracking_endid_div").style.display="none";
  2455. document.getElementById("label_id_div").style.display="none";
  2456. document.getElementById("labelOption_div").style.display="none";
  2457. if(modelid == 5 || modelid == 6 || modelid == 7 ){
  2458. //document.getElementById("labelOption").innerHTML="<option value=\"2\" selected=\"\">请选择</option> <option value=\"3\">识别车的类型与颜色</option>";
  2459. }
  2460. }
  2461. }
  2462. function export_attribute(){
  2463. var url = ip + "/api/task-export-label-property/";
  2464. var $iframe = $('<iframe />');
  2465. var $form = $('<form method="get" target="_self"/>');
  2466. $form.attr('action', url); //设置get的url地址
  2467. $form.append('<input type="hidden" name="task_id" value="' + label_task + '" />');
  2468. $form.append('<input type="hidden" name="type" value="labeltask" />');
  2469. $iframe.append($form);
  2470. $(document.body).append($iframe);
  2471. $form[0].submit();//提交表单
  2472. $iframe.remove();//移除框架
  2473. }
  2474. function import_attribute(){
  2475. $('#datasetModal').modal('show');
  2476. }
  2477. function submit_import_property(){
  2478. var jsonContent = $("#jsoninput").val();
  2479. if(!isJSON(jsonContent)){
  2480. alert("输入格式非法。");
  2481. return;
  2482. }
  2483. $.ajax({
  2484. type:"POST",
  2485. url:ip + "/api/task-import-label-property/",
  2486. headers: {
  2487. authorization:token,
  2488. },
  2489. dataType:"json",
  2490. data:{
  2491. 'jsonContent':jsonContent,
  2492. 'taskType':"labeltask",
  2493. 'taskId':label_task
  2494. },
  2495. async:false,
  2496. success:function(json){
  2497. console.log(json);
  2498. },
  2499. error:function(response) {
  2500. redirect(response);
  2501. }
  2502. });
  2503. $('#datasetModal').modal('hide');
  2504. close_attribute();
  2505. }
  2506. function isJSON(str) {
  2507. if (typeof str == 'string') {
  2508. try {
  2509. var obj=JSON.parse(str);
  2510. if(typeof obj == 'object' && obj ){
  2511. return true;
  2512. }else{
  2513. return false;
  2514. }
  2515. } catch(e) {
  2516. console.log('error:'+str+'!!!'+e);
  2517. return false;
  2518. }
  2519. }
  2520. console.log('It is not a string!');
  2521. return false;
  2522. }
  2523. img.onload = function(){
  2524. loadFinished = false;
  2525. // 初始设置画布大小,最大值宽和高
  2526. canvas.width = img.width;// maxWidth document.getElementById("tool0").offsetWidth;
  2527. canvas.height =img.height;//maxHeight document.getElementById("tool0").offsetWidth/1280*720;
  2528. //调整画布大小
  2529. if ((img.width/img.height)<(canvas.width/canvas.height)){
  2530. canvas.width=canvas.height * img.width / img.height;
  2531. }
  2532. else{
  2533. canvas.height=canvas.width * img.height / img.width;
  2534. }
  2535. maxIdNum=0;
  2536. parse_labelinfo(labeltastresult[fileindex].label_info);
  2537. drawRect();
  2538. $('#filepanel').slimScroll({
  2539. alwaysVisible: true, //是否 始终显示组件(未更改库文件时,鼠标移开滚动条消失)
  2540. });
  2541. canvas.onmousewheel = canvas.onwheel = function (event) { //滚轮放大缩小
  2542. console.log("primivate x,y=" + event.clientX + "," + event.clientY);//鼠标在屏幕上的位置
  2543. event.wheelDelta = event.wheelDelta ? event.wheelDelta : (event.deltalY * (-40)); //获取当前鼠标的滚动情况
  2544. if (event.wheelDelta > 0) {// 放大
  2545. imgScale +=0.1;
  2546. console.log("imgScale=" + imgScale);
  2547. } else {// 缩小
  2548. imgScale -=0.1;
  2549. if(imgScale< 1) {//最小缩放1
  2550. imgScale = 1;
  2551. }
  2552. console.log("imgScale=" + imgScale);
  2553. }
  2554. drawRect(); //重新绘制图片
  2555. };
  2556. loadFinished=true;
  2557. };
  2558. document.onkeydown = function(e){
  2559. switch(e.keyCode){
  2560. case 37:
  2561. case 38:
  2562. case 39:
  2563. case 40:
  2564. e.preventDefault();
  2565. }
  2566. }
  2567. document.onkeyup=function(e){
  2568. console.log(e.keyCode)
  2569. console.log(window.event);
  2570. e=e||window.event;
  2571. e.preventDefault();
  2572. obj = e.srcElement||e.target;
  2573. if( obj != null && obj !=undefined ){
  2574. if(obj.type == "textarea" || obj.type=='text'){
  2575. //console.log("obj.type:"+obj.type);
  2576. return ;
  2577. }
  2578. }
  2579. switch(e.keyCode){
  2580. case 87: //W
  2581. // boxcls = classes;
  2582. createRectLabel();
  2583. break;
  2584. case 68:
  2585. deleterect();
  2586. break;
  2587. case 27:
  2588. cancel();
  2589. break;
  2590. case 83:
  2591. save();
  2592. break;
  2593. case 81:
  2594. last();
  2595. break;
  2596. case 69:
  2597. next();
  2598. break;
  2599. case 90://u
  2600. undo();
  2601. break;
  2602. case 67://c
  2603. copyOneBox();
  2604. break;
  2605. case 86://v
  2606. paste();
  2607. break;
  2608. case 37:
  2609. moveLeftSinglePx();
  2610. break;
  2611. case 38:
  2612. moveUpSinglePx();
  2613. break;
  2614. case 39:
  2615. moveRightSinglePx();
  2616. break;
  2617. case 40:
  2618. moveDownSinglePx();
  2619. break;
  2620. };
  2621. }