-
Notifications
You must be signed in to change notification settings - Fork 38
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
Added connect to Pi button #103
base: main
Are you sure you want to change the base?
Conversation
Awesome!!! |
Hey, I have added the following code from Infragram to the example file of capture. It can be found here - https://github.com/sidntrivedi012/spectral-workbench.js/blob/pi-button/examples/capture/index.html#L363-L380 . Have also included the infragram.js lib here. But, when I run index.html file of capture, it shows the following error - Any suggestions how to resolve it? Thanks :) |
I have added the following code to var infragram, boost, openInSequencer;
document.getElementById("pibutton").onclick=function connect_to_pi(){
//infragram code to connect to raspberry-pi
infragram = Infragram({
uploader: false,
processor: 'webgl',
shaderVertPath: "../../node_modules/dist/shader.vert",
shaderFragPath: "../../node_modules/dist/shader.frag"
});
var piImage = new Image();
piImage.onload = function () {
infragram.options.processor.updateImage(piImage);
};
var fetchImageInterval = setInterval(function fetchImage() {
// piImage.src = "http://pi.local/cam/cam_pic.php?time=" + new Date().getTime();
piImage.src = "../logo.png";
}, 50);
}; |
examples/capture/index.html
Outdated
if(el){ | ||
//if pi_div button does not return null | ||
document.getElementById("pi-button").addEventListener("click", function connect_to_pi() { | ||
infragram = Infragram({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, actually i don't think it's necessary to include all of Infragram here, but we can simply borrow the appropriate sections of code! Actually all we want is the function that fetches an image from the Pi. Let me highlight.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. Removing infragram initialisation from here.
examples/capture/index.html
Outdated
}; | ||
var fetchImageInterval = setInterval(function fetchImage() { | ||
// piImage.src = "http://pi.local/cam/cam_pic.php?time=" + new Date().getTime(); | ||
piImage.src = "../logo.png"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:-) you've got this part right!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks 🎉
examples/capture/index.html
Outdated
}); | ||
var piImage = new Image(); | ||
piImage.onload = function () { | ||
infragram.options.processor.updateImage(piImage); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So here, instead of instantiating Infragram
, we should add the image to the SWB canvas, so it gets grabbed and sent to the graph.
$W.ctx.drawImage(piImage, 0, 0, $W.width, 1); // this will draw it to the waterfall canvas
The only problem here is that it's actually drawing the WHOLE camera's output, squishing it to 1 pixel tall. So, see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/drawImage
Instead let's crop the source image dimensions too!
infragram.options.processor.updateImage(piImage); | |
var sourceX = 0, sourceY = 0, sourceHeight = 300, sourceWidth = 800; // although we may modify these later to match the Pi output image dimensions | |
$W.ctx.drawImage(piImage, sourceX, sourceY, sourceHeight, sourceWidth, 0, 0, $W.width, 1); // this will draw it to the waterfall canvas |
However, it seems we may also need to stop this from getting images from the webcam:
onSave: function (data) { |
So, we ought to add a conditional there that checks for a new property $W.loadingFromPi
, and when you click that button we'll set that to true
-- that way it no longer pulls from the webcam, make sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jywarren I have added a condition to onSave
:
onSave: function(data) {
if ($W.loadingfromPi == false) {
<onSave code snippet>
}
},
And assigned default value to loadingfromPi
to false
. I am setting the value of it to true when the button is being clicked.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you just push up your latest code when you have a chance? Thanks!
package.json
Outdated
"getusermedia-js": "~1.0.0", | ||
"d3": "~3.4.0" | ||
"infragram": "^0.2.1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we can remove this too!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, removing it. Thanks.
Hi @sidntrivedi012, any updates here? Thank you!!! |
Oh sorry, i see you responded yesterday. Thanks! |
@jywarren , Apologies for the delay. Have tried to fix the loopholes as pointed by you. Also, bumped some dependencies except |
Were you able to try putting this up on your own gh-pages so we can try it out live? That would be great! |
you'll have to add the node modules to the gh-pages branch and push them up too, without adding them to your main branch. It's a little finicky, but give it a try! |
@jywarren , Have pushed the code to fork's gh-pages branch. Can be seen here - https://sidntrivedi012.github.io/spectral-workbench.js/examples/capture . |
What Should I add |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I traced this a bit and found that there's a second place the image is being copied, this time to the preview window. It may not be the only issue, because i see that the graph is also not sourcing from the pi image... let me keep looking, but this definitely will help!
So, the broader issue here is that there are references to What we need, I think, is to make a new function called function getVideoEl() {
if ($W.loadingfromPi) return $W.piImage;
else return $("video")[0];
} Note I'm using the property Does this make sense, @sidntrivedi012 ? It's a change throughout the file, but then you'll be able to change any reference to the original video element to instead be to |
Hi, can you update us on progress here? Thank you!
…On Wed, Jul 31, 2019 at 10:59 AM Siddhant N Trivedi < ***@***.***> wrote:
Ok @starkblaze01 <https://github.com/starkblaze01> . I will be testing it
tonight on my local fork repo gh-pages. If it works, will make a commit.
Thanks. 🙂
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#103?email_source=notifications&email_token=AAAF6J4OP3GCJERYQGEZMTLQCGSCRA5CNFSM4IEGNJUKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD3HRDGQ#issuecomment-516886938>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAAF6J7SW2SIFPLTSLYW6XLQCGSCRANCNFSM4IEGNJUA>
.
|
@jywarren Can you please review it now? I have made the changes as suggested by you. |
Hi, Siddhant, i'm not seeing the static image load when I press Connect. Can you look and try to figure out why? Thanks! |
Sure, looking into it. |
Hey @jywarren , can you please guide me how and where to use this function? I mean where will this function be called? |
Basically all the instances of |
@jywarren
I was thinking to hard code a conditional here. Just to ask, what should we insert here if the image is being loaded from the Pi? if(getVideoEL()==$("video")[0]) window.video=video;
else <<what to use here?>> Regarding the rest, I think we can easily use a function as suggested by you. |
You can do The function should be: function getVideoEl() {
if ($W.loadingfromPi) return $W.piImage;
else return $("video")[0];
} That way it returns an image or video element no matter where you call it from. Make sense? |
@jywarren Its somewhat working. Also have made some changes in the code. Will push in a new commit. PTAL. Thanks. The problem now is that the page is distorting when one clicks connect to Pi. |
d8a0343
to
acbe4ca
Compare
I think the distortion is OK; it's mapping the aspect ratio of the source image to the area available for display. This won't affect the spectrum. Is this ready then? Let's merge it! |
@jywarren But there's a problem that unfortunately the live plot has shifted downwards. |
I think you may have updated to Bootstrap 4 somehow? And that is affecting the styling? |
@jywarren Nope, I didn't upgrade to Bootstrap 4. Maybe there's something else. Will debug it. Thanks. |
@jywarren Also, there's one more problem that even when the image is being loaded from the Pi, the plot still gets made of the image from the camera. So, as of now there are two problems :
|
@jywarren Since this thread has become very long, should we tackle the two issues(as mentioned in the above comment) emerging due to the connect to Pi feature in another PR? |
@jywarren You were right. I had upgraded bootstrap from 3.4.0 (currently being used) version to 4.3.0 . And thus, maybe the plot was being formed on the lower end. But when I installed the 3.4.0 version of bootstrap again. The video capturing stopped. |
|
Hm, how odd. Are you seeing any errors in the console?
…On Wed, Aug 28, 2019 at 11:57 AM Siddhant N Trivedi < ***@***.***> wrote:
[image: videonotworking]
<https://user-images.githubusercontent.com/31186013/63871912-69683000-c9da-11e9-94b6-c2e9d325b95e.gif>
@jywarren <https://github.com/jywarren> This is happening from when I
downgraded the version of bootstrap. Don't know why. Searching it out. Do
you have any idea why this may be occuring?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#103?email_source=notifications&email_token=AAAF6J2JMKA6BGJ7POGLLCDQG2N35A5CNFSM4IEGNJUKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD5LTMHA#issuecomment-525809180>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAAF6J6K3YEOBPVB6BW7WD3QG2N35ANCNFSM4IEGNJUA>
.
|
@jywarren Nah, no errors in the console. |
I would use the Element inspector to see if the proper canvas or video element is being displayed under the area in question. Perhaps some CSS has gone wrong? Or, can you confirm that all libraries are installed with |
@jywarren Have checked all the libraries and installed them with |
acbe4ca
to
6a765d5
Compare
@jywarren Its working now. PTAL. |
Adding the static button as of now. In this thread will work on #75.
/cc : @jywarren @starkblaze01 @Dhiraj240 @harshithpabbati