import com.googlecode.javacpp.Loader;
import com.googlecode.javacv.*;
import com.googlecode.javacv.cpp.*;
import com.googlecode.javacv.cpp.opencv_core.CvPoint;
import com.googlecode.javacv.cpp.opencv_core.CvScalar;
import com.googlecode.javacv.cpp.opencv_core.CvSeq;
import static com.googlecode.javacv.cpp.opencv_highgui.CvCapture;
import com.googlecode.javacv.cpp.opencv_core.IplImage;
import com.googlecode.javacv.cpp.opencv_core.*;
import com.googlecode.javacv.cpp.opencv_imgproc.*;
import com.googlecode.javacv.cpp.opencv_calib3d.*;
import com.googlecode.javacv.cpp.opencv_objdetect.*;
import static com.googlecode.javacv.cpp.opencv_core.cvGetSize;
import static com.googlecode.javacv.cpp.opencv_highgui.*;
public class main {
public static void main(String[] args) {
// TODO Auto-generated method stub
IplImage img = cvLoadImage("images.png");
IplImage hsvimg = cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,3);
IplImage grayimg = cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,1);
cvCvtColor(img,hsvimg,CV_BGR2HSV);
cvCvtColor(img,grayimg,CV_BGR2GRAY);
cvShowImage("Original", img);
cvShowImage("HSV", hsvimg);
cvShowImage("GRAY", grayimg);
cvWaitKey();
cvSaveImage("Original.jpg",img);
}
}
My "IPL_DEPTH_8U, CV_BGR2HSV" is not working, I took this code from YOUTUBE this tutorial I tried many times but this is not working please help me.
Related
I'm trying to create an image file of a graph with vertices,edges and weigths with JgraphX and mxGraph.
I'm new to this thing of JGraph and stuff and found a tutorial to do this.
But I can't understand why when it creates the image, it shows the vertices and edges good but the weights are "Null".
I'll post the code below together with a image.
import com.mxgraph.layout.mxCircleLayout;
import com.mxgraph.layout.mxIGraphLayout;
import com.mxgraph.util.mxCellRenderer;
import org.jgrapht.ext.JGraphXAdapter;
import org.jgrapht.graph.DefaultDirectedGraph;
import org.jgrapht.graph.DefaultDirectedWeightedGraph;
import org.jgrapht.graph.DefaultEdge;
import org.jgrapht.*;
import org.jgrapht.graph.DefaultUndirectedWeightedGraph;
import org.jgrapht.traverse.BreadthFirstIterator;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
public class JgraphTest{
DefaultDirectedWeightedGraph<String, DefaultEdge> g = new DefaultDirectedWeightedGraph<>(DefaultEdge.class);
BreadthFirstIterator bfs;
public void crearGrafo(){
g.addVertex("Ninja1");
g.addVertex("Ninja2");
g.addVertex("Ninja3");
g.addVertex("Ninja5");
g.addVertex("Ninja8");
g.addEdge("Ninja1","Ninja2");
g.addEdge("Ninja2","Ninja1");
g.addEdge("Ninja8","Ninja3");
g.addEdge("Ninja3","Ninja5");
g.setEdgeWeight("Ninja1","Ninja2",12);
g.setEdgeWeight("Ninja2","Ninja1",2);
g.setEdgeWeight("Ninja8","Ninja3",10);
}
public void mostrarGrafo() throws IOException {
JGraphXAdapter<String, DefaultEdge> graphXAdapter = new JGraphXAdapter<>(g);
mxIGraphLayout layout = new mxCircleLayout(graphXAdapter);
layout.execute(graphXAdapter.getDefaultParent());
BufferedImage image = mxCellRenderer.createBufferedImage(graphXAdapter, null, 2, Color.white, true, null);
File imgFile = new File("src/graph.jpg");
ImageIO.write(image, "JPG",imgFile );
}
}
Image created after executing the algorithm
Thank you everyone and I hope I didn't miss any information, please let me know if I forgot to post something.
Why does my armorstand teleport after relogging into my server? For example, before relogging: https://imgur.com/a/gQQcLb9, and after relogging: https://imgur.com/a/xOeAJOz. I'm trying to make it so the armorstand will teleport once you right click a bone without having to relog.
Here's my Main code:
package com.jason.sbitems;
import com.jason.sbitems.bows.Bonemerang;
import org.bukkit.ChatColor;
import org.bukkit.plugin.java.JavaPlugin;
public class SBItems extends JavaPlugin {
#Override
public void onEnable() {
getServer().getPluginManager().registerEvents(new Bonemerang(), this);
ItemManager.init();
getCommand("get").setExecutor(new GetCommand());
getServer().getConsoleSender().sendMessage(ChatColor.GREEN + "[SBItems Plugin]: Plugin is Enabled!");
}
#Override
public void onDisable() {
getServer().getConsoleSender().sendMessage(ChatColor.RED + "[SBItems Plugin]: Plugin is Disabled!");
}
}
Here's my class code:
import org.bukkit.Material;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.EulerAngle;
import org.bukkit.util.Vector;
public class Bonemerang implements Listener {
#EventHandler
public static void onPlayerInteract(PlayerInteractEvent e) {
Player p = e.getPlayer();
if (e.getAction() == Action.RIGHT_CLICK_AIR) {
if (p.getInventory().getItemInMainHand().equals(new ItemStack(Material.BONE))) {
ArmorStand stand = (ArmorStand) p.getWorld().spawnEntity(p.getLocation(), EntityType.ARMOR_STAND);
Vector teleportTo = p.getLocation().getDirection().normalize().multiply(10);
stand.hasArms();
stand.setGravity(false);
stand.setItemInHand(new ItemStack(Material.BONE));
stand.setRightArmPose(new EulerAngle(Math.toRadians(0), Math.toRadians(120), Math.toRadians(0)));
stand.teleport(p.getLocation().add(teleportTo));
}
}
}
}
Also, is there a way to make it so that it will teleport after 10 seconds?
I am making javafx cinema seat reservation system as semester project.I want to add .mp3 music so that it plays in background while application is running and performing its fuctions.I added music but what happens is when I run code applications starts and I can perform my seat selections in GUI but there is no background music.but when I click cross(close button) GUI closes and music starts playing...I only included the music code portion.have a look
import java.io.File;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import java.awt.Image;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
public class Cinemafx extends Application{
public void start(Stage primaryStage) {
try {
FileInputStream fileInputStream = new FileInputStream("song.mp3");
Player player = new Player(fileInputStream);
System.out.println("Song is playing...");
player.play();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JavaLayerException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
I am trying to get the view count of a youtube video in Jsoup. I started by getting the title which worked well but am having trouble getting the view count which is in a span class.
Here is my code so far:
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import java.io.IOException;
import java.awt.*;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class HigherOrLowerYoutube {
public static void main(String[] args) {
try {
Document doc =
Jsoup.connect("https://www.youtube.com/watchv=omlFsLz2WKM").get();
println(doc.title());
} catch (IOException e) {
e.printStackTrace();
}
}
private static void println(String string) {
System.out.println(string);
}
}
Try:
System.out.println(doc.select(".watch-view-count").first().text());
package common;
import java.awt.image.BufferedImage;
import java.io.InputStream;
import javax.imageio.ImageIO;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class ResourcesToAccess {
public static Icon sharedAbstractDownIcon;
public static Icon sharedAbstractPlayIcon;
public static Icon sharedAbstractPauseIcon;
public static Icon sharedAbstractBlackCursor;
public static Icon sharedAbstractWhiteCursor;
public ResourcesToAccess(){
InputStream is = this.getClass().getClassLoader().getResourceAsStream("/src/images/blackCursor.png");
try{
BufferedImage bi = ImageIO.read(is);
sharedAbstractBlackCursor = (Icon) new ImageIcon(bi);
new JFrame().add(new JLabel(sharedAbstractBlackCursor)).setVisible(true);
}catch(Exception e){
e.printStackTrace();
}
}
public static void main(String[] args) {
new ResourcesToAccess();
}
}
I am using this code to see whether the PNG images can be properly loaded to create JLabels, Icons, etc but I get the error that:
java.lang.IllegalArgumentException: input == null!
at javax.imageio.ImageIO.read(Unknown Source)
at common.ResourcesToAccess.<init>(ResourcesToAccess.java:21)
at common.ResourcesToAccess.main(ResourcesToAccess.java:29)
Why do I see that error message?
try with
this.getClass().getClassLoader().getResourceAsStream("images/blackCursor.png")
it is looking in your classpath so no more src directory there