frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

Open in hackernews

07-HarmonyOS5-ObjectDetection-Case

1•zhousg•7h ago
import { photoAccessHelper } from '@kit.MediaLibraryKit' import { fileIo } from '@kit.CoreFileKit' import image from '@ohos.multimedia.image' import { objectDetection, visionBase } from '@kit.CoreVisionKit' import { promptAction } from '@kit.ArkUI';

const LabelMap: Record<number, string> = { 0: "风景", 1: "动物", 2: "植物", 3: "建筑", 5: "人脸", 6: "表格", 7: "文本", 8: "人头", 9: "猫头", 10: "狗头", 11: "食物", 12: "汽车", 13: "人体", 21: "文档", 22: "卡证" };

@Entry @ComponentV2 struct ObjectDetection { @Local chooseImage?: PixelMap @Local objects: objectDetection.VisionObject[] = [] @Local canvasWidth: number = 320 @Local canvasHeight: number = 200 @Local bozaiImage?: PixelMap

  async aboutToAppear(): Promise<void> {
    const resManager = getContext()
      .resourceManager
    const bozaiArray = await resManager.getMediaContent($r('app.media.bozai'))
    const bozaiResource = image.createImageSource(bozaiArray.buffer)
    this.bozaiImage = await bozaiResource.createPixelMap()
  }

  async checkImage() {
    // 1. 选择图片
    const photoPicker = new photoAccessHelper.PhotoViewPicker()
    const result = await photoPicker.select({
      MIMEType: photoAccessHelper.PhotoViewMIMETypes.IMAGE_TYPE,
      maxSelectNumber: 1
    })
    const uri = result.photoUris[0]
    if (uri) {
      const imageFile = await fileIo.open(uri, fileIo.OpenMode.READ_ONLY)
      const imageSource = image.createImageSource(imageFile.fd)
      this.chooseImage = await imageSource.createPixelMap()

      // 2. 进行识别
      const request: visionBase.Request = {
        inputData: { pixelMap: this.chooseImage }
      }
      if (canIUse('SystemCapability.AI.Vision.ObjectDetection')) {
        const objectDetector = await objectDetection.ObjectDetector.create()
        const data = await objectDetector.process(request)
        this.objects = data.objects

        // 3. 绘制识别区域
        const imageInfo = await this.chooseImage.getImageInfo()
        const ratio = 320 / imageInfo.size.width
        this.canvasHeight = imageInfo.size.height * ratio
        this.canvasContext.drawImage(this.chooseImage, 0, 0, this.canvasWidth, this.canvasHeight)
        this.objects.forEach(item => {
          if (item.labels.includes(5)) {
            const box = item.boundingBox
            this.canvasContext.drawImage(this.bozaiImage, box.left * ratio - ( box.height * ratio * 0.15 ), box.top * ratio, box.height * ratio,
              box.height * ratio)
          }
          // const box = item.boundingBox
          // this.canvasContext.strokeStyle = '#FF0000'
          // this.canvasContext.strokeRect(box.left * ratio, box.top * ratio, box.width * ratio, box.height * ratio);
        })
      }
    }
  }

  private settings: RenderingContextSettings = new RenderingContextSettings(true);
  private canvasContext: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings);

  build() {
    Column({ space: 20 }) {
      Canvas(this.canvasContext) {

      }
      .width(this.canvasWidth)
      .height(this.canvasHeight)
      .backgroundColor('#CCCCCC')

      Button('选择图片,进行识别')
        .onClick(() => {
          this.checkImage()
        })
      List({ space: 20 }) {
        ForEach(this.objects, (item: objectDetection.VisionObject) => {
          ListItem() {
            Column() {
              Text('可信度:' + item.score)
                .width('100%')
              Text('标签:' + item.labels.map(label => LabelMap[label])
                .join(','))
                .width('100%')
              Text('尺寸:' + JSON.stringify(item.boundingBox))
                .width('100%')
            }
          }
        })
      }
      .width('100%')
      .height('100%')
      .layoutWeight(1)
    }
    .padding(15)
    .height('100%')
    .width('100%')
  }
}

I Racked up 200 Hours on Wingspan

https://sites.uwm.edu/digital-cultures-collaboratory/2021/04/26/how-i-raked-up-200-hours-on-wingspan/
1•herbertl•1m ago•0 comments

Show HN: Trieve CLI – Terminal-Based LLM Agent Loop and Search on Any PDF

https://www.npmjs.com/package/trieve-cli
1•skeptrune•1m ago•0 comments

Python Is Removing GIL, Gradually

https://medium.com/techtofreedom/python-is-removing-gil-gradually-b41274fa62a4
1•thunderbong•3m ago•0 comments

BT chief says AI could deliver more job cuts, hints at Openreach sell-off

https://www.theregister.com/2025/06/16/bt_chief_says_ai_could_cut_more_staff/
1•rntn•5m ago•0 comments

Summer of Making 2025 – Code Projects and Win Prizes (For Kids <= 18)

https://summer.hack.club/fn
1•avipars•5m ago•0 comments

Handcrafted work is the foundation of success

https://mastersofscale.com/brian-chesky/
1•rafaepta•7m ago•0 comments

What Happened to Working Your Way Up from the Mailroom?

https://www.thediff.co/archive/what-happened-to-working-your-way-up-from-the-mailroom/
2•jger15•8m ago•0 comments

Show HN: dk – A script runner and cross-compiler, written in OCaml

https://diskuv.com/dk/help/latest/
3•beckford•8m ago•0 comments

The most-visited museum shuts down, sounding the alarm on overtourism

https://apnews.com/article/louvre-museum-paris-closed-lines-delay-2bbf9be4f49de739fd14dd4d908e4d72
3•rwc9•9m ago•0 comments

Stretchly: A cross-platform open-source app that reminds you to take breaks

https://hovancik.net/stretchly/
1•sea-gold•11m ago•0 comments

Truckloads of Scotland's rubbish will be sent to England, experts say

https://www.bbc.com/news/articles/c0r1de24pdgo
1•RickJWagner•12m ago•0 comments

Basics of Linux Shell and Shell Scripts

https://laihoconsulting.com/blog/2025-06-basics-of-linux-shell-and-shell-scripts/
1•speckx•12m ago•0 comments

Keeping Up with Dependency Updates

https://dhruvs.space/posts/keeping-up-with-dependency-updates/
2•dhth•14m ago•1 comments

Implementing dependent types in pi-forall (2023)

https://arxiv.org/abs/2207.02129
1•fanf2•16m ago•0 comments

The first cut is to ResearchOps, and how to avoid it

https://medium.com/researchops-community/the-first-cut-is-to-researchops-and-how-to-avoid-it-with-kate-towsey-4b86eaccb5b9
1•adrianhoward•18m ago•0 comments

Not Yet

https://anandsanwal.me/not-yet/
1•herbertl•18m ago•0 comments

Trump Organization announces mobile plan, $499 smartphone

https://www.cnbc.com/2025/06/16/trump-mobile-phone-plan.html
6•srueg•20m ago•1 comments

Mozilla frets about Google's push to build AI into Chrome

https://www.theregister.com/2025/06/11/mozilla_worries_googles_browser_ai/
1•Vinnl•21m ago•1 comments

Trump Mobile Launches a Bold New Wireless Service for Americans

https://www.trump.com/media/trump-mobile-launches-a-bold-new-wireless-service
4•TowerTall•24m ago•4 comments

How the first electric grid was built

https://www.worksinprogress.news/p/how-the-worlds-first-electric-grid
4•bensouthwood•24m ago•0 comments

Securing Microservices with C# Records: The Immutability Advantage

https://medium.com/devsecops-ai/securing-microservices-with-c-records-the-immutability-advantage-0a7a4f09adbf
1•herbertmoroni•24m ago•0 comments

How to build the best keyboard in the world

https://www.theverge.com/tech/686441/norbauer-seneca-keyboard-creator
2•cainxinth•25m ago•0 comments

New York Requiring Companies to Reveal If AI Caused Layoffs

https://www.entrepreneur.com/business-news/new-york-requiring-companies-to-reveal-if-ai-caused-layoffs/493267
3•speckx•26m ago•0 comments

Objex Link S3LW ultra-low-power ESP32-S3 LoRaWAN board takes up to 100W DC input

https://www.cnx-software.com/2025/05/29/objex-link-s3lw-ultra-low-power-esp32-s3-lorawan-board-takes-up-to-100w-dc-input/
2•PaulHoule•28m ago•1 comments

AI Supercomputers

https://epoch.ai/data/ai-supercomputers
1•gmays•31m ago•0 comments

Ceramic optical diamond turning machine: design and development 1999 [pdf]

https://pure.tue.nl/ws/files/1328821/9903022.pdf
1•nill0•31m ago•0 comments

The Model Context Protocol (MCP)

https://www.youtube.com/watch?v=CQywdSdi5iA
1•Brysonbw•32m ago•0 comments

WhatsApp adds ads to the status screen

https://techcrunch.com/2025/06/16/whatsapp-is-adding-ads-to-the-status-screen/
3•chiwilliams•32m ago•2 comments

Show HN: Pipo360 – Now a Full Dev Workspace (Was Just AI Back End Gen Before)

https://pipo360.xyz/try
1•the_plug•34m ago•1 comments

Class Action: Drivers Sour on Lemonade for Exposing License Numbers

https://www.insurancejournal.com/news/east/2025/06/12/827280.htm
1•crescit_eundo•34m ago•0 comments