frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

Open in hackernews

06-HarmonyOS5-SubjectSegmentation-Case

1•zhousg•8h ago
This is a background replacement case based on AI basic visual services. After selecting an image from the device's photo album, it performs intelligent segmentation on the subject and supports dynamically changing the background color

// Keep the original code provided by the user intact here import { photoAccessHelper } from '@kit.MediaLibraryKit' import { fileIo } from '@kit.CoreFileKit' import image from '@ohos.multimedia.image' import { subjectSegmentation } from '@kit.CoreVisionKit' import { promptAction } from '@kit.ArkUI'

@Entry @ComponentV2 struct SubjectSegmentation { @Local chooseImage?: PixelMap @Local segmentedImage?: PixelMap @Local bgColor: ResourceColor = Color.White

  async segmentImage() {
    if (canIUse('SystemCapability.AI.Vision.SubjectSegmentation')) {
      const photoPicker: photoAccessHelper.PhotoViewPicker = new photoAccessHelper.PhotoViewPicker();
      const photoResult = await photoPicker.select({
        MIMEType: photoAccessHelper.PhotoViewMIMETypes.IMAGE_TYPE,
        maxSelectNumber: 1
      })
      const photoUri = photoResult.photoUris[0]
      const fileSource = await fileIo.open(photoUri, fileIo.OpenMode.READ_ONLY);
      const imageSource = image.createImageSource(fileSource.fd);
      this.chooseImage = await imageSource.createPixelMap();
      const visionInfo: subjectSegmentation.VisionInfo = {
        pixelMap: this.chooseImage,
      };
      try {
        const result = await subjectSegmentation.doSegmentation(visionInfo, {
          enableSubjectForegroundImage: true
        })
        this.segmentedImage = result.fullSubject.foregroundImage
      } catch (e) {
        promptAction.showToast({ message: e.message })
      }
    }
  }

  build() {
    Column({ space: 20 }) {
      Text('Original Image:')
      Image(this.chooseImage)
        .objectFit(ImageFit.Fill)
        .height('30%')
      Text('Background Removed:')
      Image(this.segmentedImage)
        .objectFit(ImageFit.Fill)
        .height('30%')
        .backgroundColor(this.bgColor)
      Button('Select Image')
        .onClick(() => this.segmentImage())
      Button('Change Background')
        .onClick(() => {
          const a = Math.round(Math.random() * 255)
          const b = Math.round(Math.random() * 255)
          const c = Math.round(Math.random() * 255)
          this.bgColor = `rgb(${a},${b},${c})`
        })
    }
    .padding(15)
    .height('100%')
    .width('100%')
  }
}

Trump Organization announces new 'Trump Mobile' phone service

https://thehill.com/policy/technology/5352259-trump-launches-trump-mobile/
1•jermaustin1•33s ago•0 comments

Income Inequality Depresses Support for Higher Minimum Wages [pdf]

https://www.apa.org/pubs/journals/releases/xge-xge0001772.pdf
1•PaulHoule•1m ago•0 comments

Amazon is reportedly training humanoid robots to deliver packages

https://www.theverge.com/news/680258/amazon-training-package-delivery-humanoid-robots
1•gmays•1m ago•0 comments

Navel Gazing and the Golden Ratio

https://www.nytimes.com/interactive/2025/06/16/science/math-strogatz-leonardo-bellybutton.html
1•ajay-d•2m ago•0 comments

State of CSS 2025 Survey

https://survey.devographics.com/en-US/survey/state-of-css/2025
1•miiiiiike•2m ago•0 comments

Study Reveals Stark Differences in Life Expectancy Across U.S. States

https://ysph.yale.edu/news-article/study-reveals-stark-differences-in-life-expectancy-across-us-states-over-the-past-century/
1•geox•2m ago•0 comments

Makers of air fryers and smart speakers told to respect users' right to privacy

https://www.theguardian.com/technology/2025/jun/16/air-fryers-smart-tv-speakers-user-data-privacy-ico
1•frereubu•2m ago•0 comments

Object personification in autism: This paper will be sad if you don't read

https://pubmed.ncbi.nlm.nih.gov/30101594/
1•oliverkwebb•2m ago•0 comments

2024 Research Leaders: Leading academic institutions

https://www.nature.com/nature-index/research-leaders/2024/institution/academic/all/global
1•surprisetalk•3m ago•0 comments

Should we design for iffy internet?

https://bytes.zone/posts/should-we-design-for-iffy-internet/
1•surprisetalk•3m ago•0 comments

The East Asian high-rise development model is catastrophic for birth rates

https://www.taipeitimes.com/News/feat/archives/2025/06/16/2003838679
2•ilamont•5m ago•0 comments

How long does it take to get good at steno?

https://stenokeyboards.com/blogs/posts/how-long-does-it-take-to-get-good-at-steno
1•tosh•7m ago•0 comments

ToposText

https://topostext.org/
1•leonry•7m ago•0 comments

Uber support doxxed us and now we have to move [video]

https://www.youtube.com/watch?v=Bx8NLOqkLVQ
2•zepton•7m ago•0 comments

Show HN: AppTrack – A Local-Only Desktop App to Organize Your Job Search

https://getapptrack.com/
1•wc_nomad•10m ago•0 comments

The Complete LLM Evaluation Playbook: How To Run LLM Evals That Matter

https://www.confident-ai.com/blog/the-ultimate-llm-evaluation-playbook
2•jeffreyip•10m ago•0 comments

America's infatuation with boy geniuses and 'Great Men' is ruining us

https://www.theguardian.com/us-news/ng-interactive/2025/jun/08/boy-geniuses-great-men-trump
3•robtherobber•11m ago•0 comments

Quitting Comfort: I'm attending Recurse

https://www.frankchiarulli.com/blog/attending-recurse/
1•fcjr•13m ago•0 comments

Homo Ignorans: Deliberately Choosing Not to Know

https://pubmed.ncbi.nlm.nih.gov/27217249/
1•ronitmndl•13m ago•0 comments

How to Out-Troll the Trolls, as Told by the Internet's Foremost Posters

https://www.wired.com/story/how-to-win-fight-online/
1•01-_-•13m ago•0 comments

watchOS 26 Moves Latest Apple Watch Models to New ARM64 Architecture

https://www.macrumors.com/2025/06/16/watchos-26-moves-apple-watch-to-new-architecture/
1•tosh•15m ago•0 comments

Australian denied entry to US after being grilled about Israel-Gaza views

https://www.abc.net.au/news/2025-06-16/australian-denied-entry-united-states-israel-gaza-columbia/105419154
3•benchtobedside•18m ago•0 comments

Confusing Innovation with 'Jugaad'

https://mukulsaxena.wordpress.com/2025/06/15/confusing-innovation-with-jugaad/
1•wavelander•18m ago•0 comments

It Costs over $4k a Year to Be a Sports Fan Now

https://www.nytimes.com/2025/06/16/opinion/sports-nba-mlb-leagues-streaming-fan.html
1•jihadjihad•18m ago•1 comments

New generation of thulium fiber lasers achieves world record performance

https://www.iof.fraunhofer.de/en/pressrelease/2025/New-generation-of-thulium-fiber-lasers-achieves-world-record-performance.html
2•nill0•20m ago•0 comments

A Whistleblower Incentive Program to Enforce U.S. Export Controls

https://www.lawfaremedia.org/article/a-whistleblower-incentive-program-to-enforce-u.s.-export-controls
1•erwald•20m ago•0 comments

Benzene at 200

https://www.chemistryworld.com/opinion/benzene-at-200/4021504.article
14•Brajeshwar•20m ago•3 comments

Hibernate Search 8.0.0.Final is out

https://in.relation.to/2025/06/06/hibernate-search-8-0-0-Final/
1•andrewstetsenko•21m ago•0 comments

AI.gov website repository

https://github.com/gsa-tts-archived/ai.gov
2•ndsipa_pomu•22m ago•1 comments

Disaster insurance payout could depend on balloons

https://www.axios.com/2025/06/16/climate-tech-startup-ai-insurance-disaster-recovery
2•Brajeshwar•23m ago•0 comments