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

detection.js 87 kB

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