Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blank Canvas after calling applyBlur() in React #1

Closed
djaffer opened this issue Oct 17, 2021 · 13 comments
Closed

Blank Canvas after calling applyBlur() in React #1

djaffer opened this issue Oct 17, 2021 · 13 comments

Comments

@djaffer
Copy link

djaffer commented Oct 17, 2021

I am trying to use this package in react? Is there anything else that has to be done other than what is in the document? The canvas is just blank after calling apply blur.

@akhil-rana
Copy link
Owner

akhil-rana commented Oct 17, 2021

Hi @djaffer
Thanks for creating the issue.

Can you please share a code snippet or repo link for me to test and try..

I haven't tested specifically on react but on vannila JS or TS projects.
If you have a code snippet I'll give it a go.

@akhil-rana
Copy link
Owner

Also I'm planning on making a react specific guide and changes soon. No ETA though.

@akhil-rana akhil-rana changed the title Is this still functioning and supported? Blank Canvas after calling applyBlur() in React Oct 17, 2021
@akhil-rana
Copy link
Owner

@djaffer
Just a note.

segmentBackground() needs to be called before applying any kind of effect. If segment background runs successfully then applyBlur() should run without any issue as it's just a css filter on top of the segments.

@djaffer
Copy link
Author

djaffer commented Oct 21, 2021

I had to pause and play again for it to take it into effect.

    segmentBackground(this.myVideoRef.current, this.myVideoCanvasRef.current);
      applyBlur(10);
      this.myVideoRef.current.pause();
  this.myVideoRef.current.play();
        ```
I do get this error often. 
![image](https://user-images.githubusercontent.com/5740725/138225127-6bd78bee-7f40-4eea-8337-61e6cdc4f6c1.png)




Couple of suggestions/Good to have.

1) Move media pipe to npm dependency so CSP issue is not there.
 it to bit 2.106577a1.chunk.js:2 Refused to load the script 'https://cdn.jsdelivr.net/npm/@mediapipe/[email protected]/selfie_segmentation.js' because it violates the following Content Security Policy directive: "script-src-elem 'self' code.jquery.com 
 https://google.github.io/mediapipe/getting_started/javascript
 
2) For image background would it be possible to rotate it in the library using package https://www.npmjs.com/package/@jimp/plugin-flip

@djaffer
Copy link
Author

djaffer commented Oct 21, 2021

Great work there!
The issue was you have an event handler on the play. The video is already playing when the background is added. I had to pause and play again for it to take it into effect.

segmentBackground(this.myVideoRef.current, this.myVideoCanvasRef.current);
applyBlur(10);
this.myVideoRef.current.pause();
this.myVideoRef.current.play();

I do get this error often.

image

Couple of suggestions/Good to have.

  1. I am getting CSP issue. Would you like to move media pipe to npm dependency so CSP issue is not there.
    it to bit 2.106577a1.chunk.js:2 Refused to load the script 'https://cdn.jsdelivr.net/npm/@mediapipe/[email protected]/selfie_segmentation.js' because it violates the following Content Security Policy directive: "script-src-elem 'self' code.jquery.com
    https://google.github.io/mediapipe/getting_started/javascript

  2. For image background would it be possible to rotate it in the library using package https://www.npmjs.com/package/@jimp/plugin-flip.

@akhil-rana
Copy link
Owner

Okay got it. Must be how react handles few things.
I'll work on this. Thanks for the feedback.

Regarding your suggestions:

  1. I know i didn't add selfie segmentation as a npm dependency. This is because mediapipe is using obfuscated JavaScript in their code. So it wasn't compatible in certain situations(using vitejs) The only way to get it to work was adding the script into the index.html file manually from the cdn link. I've also created an issue regarding this here on vite.

  2. If you just want to flip the image for the user then just use css transform: scaleX(-1); Though I might add this as customisable param in future.

@djaffer
Copy link
Author

djaffer commented Oct 21, 2021

thanks. Got it. Was there any particular reason to use Vite rather react.
Actually, I am using it in webrtc to transmit the video stream with background so I will have to create a new image flipped. This is ok I understand if you want to keep your library generic but I am not sure besides video call what other are major use.

@djaffer
Copy link
Author

djaffer commented Oct 21, 2021

thanks. Got it. Was there any particular reason to use Vite rather react.
Actually, I am using it in webrtc to transmit stream so I will have to create a new image that is flipped. This is ok I understand if you want to keep your library generic.

@akhil-rana
Copy link
Owner

Vite isn't a react replacement but a create-react-app replacement. It uses modern architecture to compile and run applications way faster when compared to CRA.

I've made it keeping mind webrtc and video calls only.
The self image should be flipped to user in a video call I think, so I'm using just css transform to flip the whole canvas in my other project.

@djaffer
Copy link
Author

djaffer commented Oct 21, 2021

thanks, but the issue on the opposite side the issue is to make it mirror mode.

@akhil-rana
Copy link
Owner

Okay. I'll add a new param to flip the background in next versions.
Thanks for the feedback.

@akhil-rana
Copy link
Owner

So if it's okay then should I close this issue for now?

@djaffer
Copy link
Author

djaffer commented Oct 25, 2021

yes I can close

@djaffer djaffer closed this as completed Oct 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants